home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume26 / most-3.2 / part01 next >
Encoding:
Text File  |  1993-04-12  |  93.3 KB  |  3,346 lines

  1. Newsgroups: comp.sources.unix
  2. From: davis@pacific.mps.ohio-state.edu (John E. Davis)
  3. Subject: v26i148: most-3.2 -- more/less replacement, V3.2, Part01/02
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: davis@pacific.mps.ohio-state.edu (John E. Davis)
  8. Posting-Number: Volume 26, Issue 148
  9. Archive-Name: most-3.2/part01
  10.  
  11. [ I renamed the aa_readme.doc file to README and I removed the preformatted
  12.   man page since there's an NROFF-style man page included.        --vix ]
  13.  
  14. MOST version 3.2 is now ready.  It is a more/less type program which runs on
  15. both VMS and unix systems.  In particular it runs on Ultrix and SunOS versions
  16. of unix.  I have also ported it to unix system 5 but due to time constraints,
  17. I removed some of the functionality.  Hence, the present version compiles only
  18. under BSD type unix systems (and, of course, VMS).  Strictly speaking, the
  19. program works only for VTxxx compatable terminals.  However, this is not as
  20. restrictive as it might at first seem since many terminals, including xterm,
  21. understand the vtxxx escape sequences.
  22.  
  23. New Features in MOST version 3.2   (June 1, 1992)
  24.  
  25. 1.  Some Bugs fixed.
  26. 2.  EDT editor keypad keymappings now available (Thanks to Mark Pizzolato)
  27. 3.  New most.1 man page (Thanks to David W. Sanderson)
  28.  
  29.      AUTHOR
  30.           John E. Davis
  31.           The Ohio State University
  32.           Department of Physics
  33.           davis@pacific.mps.ohio-state.edu
  34.  
  35. #! /bin/sh
  36. # This is a shell archive.  Remove anything before this line, then unpack
  37. # it by saving it into a file and typing "sh file".  To overwrite existing
  38. # files, type "sh file -c".  You can also feed this as standard input via
  39. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  40. # will see the following message at the end:
  41. #        "End of archive 1 (of 2)."
  42. # Contents:  MANIFEST README buffer.c buffer.h changes.txt cmd.c dir.c
  43. #   display.c display.h edit.c externs.h file.c file.h help.c keym.h
  44. #   line.c line.h main.c make.com makecom.com makefile most.c most.h
  45. #   rtl.opt search.c search.h sysdep.h window.h
  46. # Wrapped by vixie@gw.home.vix.com on Tue Apr 13 13:04:52 1993
  47. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  48. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  50. else
  51. echo shar: Extracting \"'MANIFEST'\" \(1088 characters\)
  52. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  53. X   File Name        Archive #    Description
  54. X-----------------------------------------------------------
  55. X MANIFEST                   1    
  56. X README                     1    
  57. X buffer.c                   1    
  58. X buffer.h                   1    
  59. X changes.txt                1    
  60. X cmd.c                      1    
  61. X dir.c                      1    
  62. X display.c                  1    
  63. X display.h                  1    
  64. X edit.c                     1    
  65. X externs.h                  1    
  66. X file.c                     1    
  67. X file.h                     1    
  68. X help.c                     1    
  69. X keym.c                     2    
  70. X keym.h                     1    
  71. X line.c                     1    
  72. X line.h                     1    
  73. X main.c                     1    
  74. X make.com                   1    
  75. X makecom.com                1    
  76. X makefile                   1    
  77. X most.1                     2    
  78. X most.c                     1    
  79. X most.h                     1    
  80. X rtl.opt                    1    
  81. X search.c                   1    
  82. X search.h                   1    
  83. X sysdep.c                   2    
  84. X sysdep.h                   1    
  85. X window.c                   2    
  86. X window.h                   1    
  87. END_OF_FILE
  88. if test 1088 -ne `wc -c <'MANIFEST'`; then
  89.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  90. fi
  91. # end of 'MANIFEST'
  92. fi
  93. if test -f 'README' -a "${1}" != "-c" ; then 
  94.   echo shar: Will not clobber existing file \"'README'\"
  95. else
  96. echo shar: Extracting \"'README'\" \(2347 characters\)
  97. sed "s/^X//" >'README' <<'END_OF_FILE'
  98. The following files should be present in this distribution:
  99. X
  100. X    aaa_read.me   ---  This file (called README in the comp.sources.unix relse)
  101. X
  102. X    most.c main.c buffer.c file.c window.c display.c sysdep.c keym.c
  103. X    search.c help.c edit.c dir.c cmd.c line.c --- C files
  104. X
  105. X    most.h buffer.h file.h window.h display.h sysdep.h keym.h
  106. X    search.h externs.h  --- Header files
  107. X
  108. X    makefile      --  makefile for unix systems
  109. X    make.com      --  `makefile' for VMS
  110. X    rtl.opt       --  options file for VMS linking
  111. X    changes.txt   --  summary of recent changes
  112. X    most.doc      --  main documentation for most
  113. X    most.1        --  nroff source
  114. X
  115. X
  116. To make MOST requires an ansi compatable c compiler.  It compiles fine with
  117. X`cc most.c' on Ultrix and VMS, and `CC +V most.c -o most' on a sun4.
  118. Other than this, I do not know what else to say.
  119. X
  120. X                          INSTALLATION INSTRUCTIONS
  121. X
  122. On VMS, type `@make' at the DCL prompt to build most.  On unix, `make' should
  123. work--- if not, the makefile may need edited.
  124. X                          
  125. Then to run most, just type `most "filename"' (eg. `most login.com').
  126. X
  127. MOST has online help which is invoked with the `h' key.  To get online help
  128. functioning properly, the logical name `MOST_HELP' must be defined to point
  129. the correct doc file.  To do this, put the following in your .cshrc (or equiv)
  130. file:
  131. X
  132. setenv MOST_HELP <directory of most.help>most.doc
  133. X
  134. and if you are on VMS put
  135. X
  136. X$ define/nolog MOST_HELP <directory of most.help>MOST.DOC
  137. X
  138. XFor example, I have
  139. X
  140. setenv MOST_HELP /u2/davis/most/most.doc
  141. X
  142. in my .cshrc on a unix host.
  143. X
  144. The other logical that most reads is `MOST_SWITCHES'.  This allows the user to
  145. run MOST with whatever switches are defined by this logical.  I use most with
  146. the -s and -c switches so I have
  147. X
  148. setenv MOST_SWITCHES "-sca"
  149. X
  150. in my .cshrc file for unix and
  151. X
  152. X$ define/nolog MOST_SWITCHES "-sca"
  153. X
  154. in my login.com file on VMS.
  155. X
  156. X
  157. I suggest that you first build MOST then view the doc file using MOST (`most
  158. most.doc').  If you need help, hit the `h' key from within MOST.  The `h' key
  159. simply locates the part of the doc file that describes what the various key
  160. do.  One person has suggested that I use a one page help screen.  However, I
  161. chose not to do this.  Most has very few key sequences to memorize and the one
  162. page help screen will quickly outgrow it usefulness.
  163. END_OF_FILE
  164. if test 2347 -ne `wc -c <'README'`; then
  165.     echo shar: \"'README'\" unpacked with wrong size!
  166. fi
  167. # end of 'README'
  168. fi
  169. if test -f 'buffer.c' -a "${1}" != "-c" ; then 
  170.   echo shar: Will not clobber existing file \"'buffer.c'\"
  171. else
  172. echo shar: Extracting \"'buffer.c'\" \(9310 characters\)
  173. sed "s/^X//" >'buffer.c' <<'END_OF_FILE'
  174. X#include "buffer.h"
  175. X#include "externs.h"
  176. X#include "display.h"
  177. X#include "line.h"
  178. X  
  179. int MOST_W_OPT = 0;
  180. X
  181. unsigned char *BEG;             /* beginning of current buffer */
  182. unsigned char *EOB;             /* end of current buffer */
  183. unsigned char MINI_BUF[132];
  184. X
  185. Buffer *BUF;
  186. X
  187. extern int SQUEEZE_LINES;
  188. int NUM_LINES;
  189. int ACTUAL_LINES;
  190. X
  191. unsigned char *C_POS;
  192. int C_LINE;
  193. X
  194. unsigned char *beg_of_line1()
  195. X{
  196. X    unsigned char *pos;
  197. X    
  198. X    if (C_POS == BEG) return BEG;
  199. X
  200. X    pos = C_POS;
  201. X    if (pos == EOB) pos--;
  202. X
  203. X    if ((*pos != '\n') && (*(pos-1) == '\n')) return(pos);
  204. X    
  205. X    if ((*pos == '\n') && (pos == BEG)) return(BEG);
  206. X    /* suppose BEG[] is "....\nabcde\n\n\n\n\n..." and we are somwhere in
  207. X       the middle of the \n's.  Then we want to return the 2nd \n if the
  208. X       SQUEEZE is on otherwise just return where we are. */
  209. X    if ((*pos-- == '\n') && (*pos == '\n'))
  210. X      {
  211. X          if (SQUEEZE_LINES)
  212. X            {
  213. X                /* if we are between '\n's then skip past all of them. */
  214. X                while ((pos > BEG) && (*pos == '\n')) pos--;
  215. X                if ((pos == BEG) && (*pos == '\n')) return (BEG);
  216. X                pos++;
  217. X            }
  218. X          return (++pos);
  219. X      }      
  220. X    
  221. X    while((pos > BEG) && (*pos != '\n')) pos--;
  222. X    if (pos != BEG) pos++;
  223. X    else if ((pos == BEG) && (*pos == '\n')) pos++;
  224. X    return pos;
  225. X}
  226. X
  227. unsigned char *beg_of_line()
  228. X{
  229. X    unsigned char *b;
  230. X    int d,n;
  231. X    
  232. X    if (!MOST_W_OPT) return beg_of_line1();
  233. X    b = beg_of_line1();
  234. X    d = C_POS - b;
  235. X    n = d / SCREEN_WIDTH_M1;
  236. X    return(b +  (int) (n * SCREEN_WIDTH_M1));
  237. X}
  238. X
  239. X/* does not move point */
  240. unsigned char *end_of_line1()
  241. X{
  242. X    unsigned char *pos;
  243. X
  244. X    pos = C_POS;
  245. X    if (pos >= EOB)  return(EOB);
  246. X    /*     if ((pos == BEG) && (*pos == '\n')) return (BEG); */
  247. X    
  248. X    /* find the first '\n' */
  249. X    if (*pos != '\n')
  250. X      {
  251. X          while ((pos < EOB) && (*pos != '\n')) pos++;
  252. X          return(pos);
  253. X      }
  254. X    
  255. X    if (!SQUEEZE_LINES) return (pos);
  256. X
  257. X    /* if BEG = "....abc\n\n\n\n\ndef..." then we are at some first \n.  We
  258. X       want to return the last '\n' unless we wre at the first '\n'. */
  259. X
  260. X    if ((pos > BEG) && ( pos--, *pos++ != '\n')) return (pos); 
  261. X    
  262. X    while ((pos < EOB) && (*pos == '\n')) pos++;
  263. X    if (pos-- == EOB) return (pos);
  264. X    if (pos < BEG) pos = BEG;
  265. X    return pos;
  266. X}
  267. X
  268. unsigned char *end_of_line()
  269. X{
  270. X    unsigned char *b, *e;
  271. X    int n;
  272. X    
  273. X    if (!MOST_W_OPT) return end_of_line1();
  274. X
  275. X    b = beg_of_line();
  276. X    e = end_of_line1();
  277. X    n = (e - b) / SCREEN_WIDTH_M1;
  278. X    if (n) return(b + SCREEN_WIDTH_M1);
  279. X    return (e);
  280. X}
  281. X
  282. int forward_line(int n)
  283. X{
  284. X    int m, ok;
  285. X    int save = n;
  286. X    unsigned char *p;
  287. X    if (n > 0) 
  288. X      {
  289. X          if (MOST_B_OPT)
  290. X            {
  291. X                m = (EOB - C_POS)/16;
  292. X                if (n > m) n = m;
  293. X                C_POS += n * 16;
  294. X                C_LINE += n;
  295. X                return n;
  296. X            }
  297. X          else while (n--)
  298. X            {
  299. X                C_POS = end_of_line();
  300. X                /* next step handles newline at the EOB */
  301. X                if ((C_POS == EOB) || ((C_POS == EOB - 1) && (*C_POS == '\n'))) return (save - n - 1);
  302. X                C_LINE++;
  303. X                C_POS++;
  304. X                if (MOST_S_OPT)
  305. X                  {
  306. X                      p = C_POS;
  307. X                      ok = 1;
  308. X                      while ((*p <= ' ') && ok)
  309. X                        {
  310. X                            if (*p != '\n') p++;
  311. X                            if (p >= EOB) break;
  312. X                            if ((*p == '\n') || (apparant_distance(p) >= MOST_S_OPT))
  313. X                              {
  314. X                                  ok = 0;
  315. X                                  C_LINE--;
  316. X                                  n++;
  317. X                              }
  318. X                        }
  319. X                  } /* MOST_S_OPT */
  320. X            }
  321. X      }
  322. X    else
  323. X      {
  324. X          if (MOST_B_OPT)
  325. X            {
  326. X                m = (BEG - C_POS)/16;
  327. X                if (n < m) n = m;
  328. X                C_POS += n * 16;
  329. X                C_LINE += n;
  330. X                return n;
  331. X            }
  332. X          else while (n++)
  333. X            {
  334. X                C_POS = beg_of_line();
  335. X                if (C_POS == BEG) return (n - save - 1);
  336. X                C_POS--;
  337. X                C_LINE--;
  338. X                if (MOST_S_OPT)
  339. X                  {
  340. X                      C_POS = beg_of_line();
  341. X                      p = C_POS;
  342. X                      ok = 1;
  343. X                      while ((*p <= ' ') && ok)
  344. X                        {
  345. X                            if (*p != '\n') p++;
  346. X                            if (p >= EOB) break;
  347. X                            if ((*p == '\n') || (apparant_distance(p) >= MOST_S_OPT))
  348. X                              {
  349. X                                  ok = 0;
  350. X                                  C_LINE++;
  351. X                                  n--;
  352. X                              }
  353. X                        }
  354. X                  } /* MOST_S_OPT */
  355. X            }
  356. X      }
  357. X    return(save);
  358. X}
  359. X
  360. int count_lines(unsigned char *beg, unsigned char *end)
  361. X{
  362. X    int save_line = C_LINE, n;
  363. X    unsigned char *save_beg = beg, *save_eob = EOB, *save_pos = C_POS;
  364. X
  365. X    if (MOST_B_OPT) return((int)(end - beg) / 16);
  366. X    BEG = C_POS = beg;
  367. X    EOB = end;
  368. X    n = 1;
  369. X    while(forward_line(1)) n++;
  370. X    if (*end ==  '\n') n--;
  371. X    if (!n) n = 1;
  372. X    C_POS = save_pos;
  373. X    EOB = save_eob;
  374. X    BEG = save_beg;
  375. X    C_LINE = save_line;
  376. X    return(n);
  377. X}
  378. X
  379. void goto_line(int line)
  380. X{
  381. X    register int i,j;
  382. X    unsigned char *pos;
  383. X    int dif_c, dif_b,dif_t;
  384. X
  385. X    if (line < 1) line = 1;
  386. X    if (line > NUM_LINES) line = NUM_LINES;
  387. X
  388. X    if (MOST_B_OPT)
  389. X      {
  390. X          C_POS = BEG + (16 * (line - 1));
  391. X          C_LINE = line;
  392. X          return;
  393. X      }
  394. X    
  395. X    dif_c = line - C_LINE;
  396. X    dif_b = line - NUM_LINES;
  397. X    dif_t = line - 1;
  398. X
  399. X    /* 4 possibilites */
  400. X    if (dif_c <= 0)
  401. X      {
  402. X          if (dif_t < -dif_c) /* go from top */
  403. X            {
  404. X                C_LINE = 1;
  405. X                C_POS = BEG;
  406. X                (void) forward_line(dif_t);
  407. X            }
  408. X          else  /* from curr back */
  409. X            {
  410. X                (void) forward_line(dif_c);
  411. X            }
  412. X      }
  413. X    else if (dif_c > 0)
  414. X      {
  415. X          if ((dif_c + dif_b) < 0) /* go from curr */
  416. X            {
  417. X                (void) forward_line(dif_c);
  418. X            }
  419. X          else
  420. X            {
  421. X                C_LINE = NUM_LINES;
  422. X                C_POS = EOB;
  423. X                (void) forward_line(dif_b);
  424. X            }
  425. X      }
  426. X}       
  427. X
  428. X/* return line the point is on without the final '\n's
  429. X    unless beg = end in which case we take care of it later ...
  430. X
  431. X    returns 1 if the line should be wrapped */
  432. int extract_line(unsigned char **beg, unsigned char **end)
  433. X{
  434. X    *beg = beg_of_line();
  435. X    *end = end_of_line();
  436. X    if (**end != '\n') return(1);
  437. X    while ((*end > BEG) && (**end == '\n')) *end = *end - 1;
  438. X    return(0);
  439. X}    
  440. X
  441. int what_line(unsigned char *pos)
  442. X{
  443. X    
  444. X    unsigned char *save_pos;
  445. X    int save_line, dir;
  446. X    register int dif_c, dif_b,dif_t;
  447. X    int ret;
  448. X
  449. X    if (MOST_B_OPT)
  450. X      {
  451. X          return (1 + (pos - BEG)/16);
  452. X      }
  453. X    
  454. X        
  455. X    save_pos = C_POS;
  456. X    save_line = C_LINE;
  457. X    
  458. X    dif_c = pos - C_POS;
  459. X    dif_b = pos - EOB;
  460. X    dif_t = pos - BEG;
  461. X
  462. X    /* 4 possibilites */
  463. X    if (dif_c <= 0)
  464. X      {
  465. X          if (dif_t < -dif_c) /* go from top */
  466. X            {
  467. X                C_LINE = 1;
  468. X                C_POS = BEG;
  469. X                dir = 1;
  470. X            }
  471. X          else  /* from curr back */
  472. X            {
  473. X                dir = -1;
  474. X            }
  475. X      }
  476. X    else if (dif_c > 0)
  477. X      {
  478. X          if ((dif_c + dif_b) < 0) /* go from curr */
  479. X            {
  480. X                dir = 1;
  481. X            }
  482. X          else
  483. X            {
  484. X                C_LINE = NUM_LINES;
  485. X                C_POS = EOB;
  486. X                dir = -1;
  487. X            }
  488. X      }
  489. X    if (dir == 1)
  490. X      {
  491. X          while(C_POS = end_of_line(), C_POS < pos)
  492. X            {
  493. X                C_POS++;
  494. X                C_LINE++;
  495. X            }
  496. X      }
  497. X    else
  498. X      {
  499. X          while(C_POS = beg_of_line(), pos < C_POS)
  500. X            {
  501. X                C_LINE--;
  502. X                C_POS--;
  503. X            }
  504. X      }
  505. X
  506. X    ret = C_LINE;
  507. X    C_POS = save_pos;
  508. X    C_LINE = save_line;
  509. X    return(ret);
  510. X}
  511. X
  512. X/* given a buffer position, find the line and column */
  513. void find_row_column(unsigned char *pos, int *r, int *c)
  514. X{
  515. X    unsigned char *beg, *save_pos;
  516. X    int save_line;
  517. X
  518. X
  519. X    if (pos <= BEG)
  520. X      {
  521. X          *r = 1;
  522. X          *c = 1;
  523. X          return;
  524. X      }
  525. X
  526. X    save_line = C_LINE;
  527. X    save_pos = C_POS;
  528. X    *r = what_line(pos);
  529. X    
  530. X    if (MOST_B_OPT)
  531. X      {
  532. X          *c = (int) (pos - BEG) - *r * 16 + 1;
  533. X          return;
  534. X      }
  535. X    C_LINE = *r;
  536. X    C_POS = pos;
  537. X    
  538. X    /* Now we have found the line it is on so.... */
  539. X    beg = beg_of_line();
  540. X    *c = 1;
  541. X    while (beg++ < pos) *c = *c + 1;
  542. X    C_LINE = save_line;
  543. X    C_POS = save_pos;
  544. X}       
  545. X
  546. Buffer *switch_to_buffer(Buffer *new)
  547. X{
  548. X    Buffer *old;
  549. X    old = BUF;
  550. X    BUF = new;
  551. X    BEG = BUF->beg;
  552. X    EOB = BUF->end;
  553. X    return(old);
  554. X}
  555. X
  556. void delete_buffer(Buffer *old)
  557. X{
  558. X    (void) free(BUF);
  559. X    BUF = old;
  560. X    BEG = BUF->beg;
  561. X    EOB = BUF->end;
  562. X}
  563. X
  564. Buffer *create_buffer(char *file)
  565. X{
  566. X    Buffer *buf;
  567. X
  568. X    buf = (Buffer *) malloc(sizeof(Buffer));
  569. X    strcpy(buf->file,file);
  570. X    return(buf);
  571. X}
  572. END_OF_FILE
  573. if test 9310 -ne `wc -c <'buffer.c'`; then
  574.     echo shar: \"'buffer.c'\" unpacked with wrong size!
  575. fi
  576. # end of 'buffer.c'
  577. fi
  578. if test -f 'buffer.h' -a "${1}" != "-c" ; then 
  579.   echo shar: Will not clobber existing file \"'buffer.h'\"
  580. else
  581. echo shar: Extracting \"'buffer.h'\" \(2037 characters\)
  582. sed "s/^X//" >'buffer.h' <<'END_OF_FILE'
  583. X#ifndef _DAVIS_BUFFER_H_
  584. X#define _DAVIS_BUFFER_H_
  585. X
  586. typedef struct
  587. X  {
  588. X      char file[80];            /* filename */
  589. X      unsigned char *beg;       /* beginning of buffer */
  590. X      unsigned char *end;       /* end of buffer */
  591. X      int mark;                 /* marked line in buffer */
  592. X  } Buffer;
  593. X
  594. X
  595. extern int NUM_LINES;
  596. extern Buffer *BUF;
  597. extern unsigned char *BEG, *EOB;
  598. extern unsigned char MINI_BUF[132];
  599. X/* The buffer.
  600. X
  601. X   The beginning of the first character is at BUF.  The last character
  602. X   in the file is located at position EOB-1.  So if we are at position EOB,
  603. X   then we can insert a character past the last point.  EOB = BUF + BUF_SIZE;
  604. X.
  605. X*/
  606. X  
  607. extern unsigned char *C_POS;
  608. X/* 
  609. X *  current position of point.  Considered to be between the previous
  610. X *  character and the next character.  There is no current character.
  611. X *  If we are at the beginning of the buffer BUF, then its value is BUF.
  612. X *  If we are at the end of the buffer it is BUF + BUF_SIZE = EOB.
  613. X */
  614. X
  615. extern int C_LINE;
  616. X/* 
  617. X *  Current line number.  If at the beginning of the buffer, it is 1.  If
  618. X *  we are at the last point of the buffer it is the number of lines.
  619. X */
  620. X
  621. X/* These two routines do not move the point */  
  622. extern unsigned char *beg_of_line();
  623. extern unsigned char *end_of_line();
  624. X
  625. extern int forward_line(int);
  626. X/* This routine moves the point forward n lines. n can be negative. 
  627. X   It returns the number moved. */
  628. X
  629. extern void goto_line(int);
  630. X/* Move the point somewhere on the nth line of the buffer returning
  631. X   C_POS */
  632. X
  633. extern int what_line(unsigned char *);
  634. X/* return the line number of position 'argument'. Does not move point */
  635. X
  636. X/* count the number of lines in the region delimited by beg and end.
  637. X   Counts lines from beg up to end but does not count end.
  638. X   Does not move point. */
  639. extern int count_lines(unsigned char *, unsigned char *);
  640. extern int extract_line(unsigned char **, unsigned char **);
  641. X
  642. extern Buffer *switch_to_buffer(Buffer *);
  643. extern void delete_buffer(Buffer *);
  644. extern Buffer *create_buffer(char *);
  645. X
  646. X
  647. X#endif
  648. X  
  649. END_OF_FILE
  650. if test 2037 -ne `wc -c <'buffer.h'`; then
  651.     echo shar: \"'buffer.h'\" unpacked with wrong size!
  652. fi
  653. # end of 'buffer.h'
  654. fi
  655. if test -f 'changes.txt' -a "${1}" != "-c" ; then 
  656.   echo shar: Will not clobber existing file \"'changes.txt'\"
  657. else
  658. echo shar: Extracting \"'changes.txt'\" \(264 characters\)
  659. sed "s/^X//" >'changes.txt' <<'END_OF_FILE'
  660. New Features in MOST version 3.2   (June 1, 1992)
  661. X
  662. X1.  Some Bugs fixed.
  663. X2.  EDT editor keypad keymappings now available (Thanks to Mark Pizzolato)
  664. X3.  New most.1 man page (Thanks to David W. Sanderson)
  665. X
  666. John E. Davis
  667. davis@amy.tch.harvard.edu
  668. davis@ohstpy.bitnet
  669. X
  670. END_OF_FILE
  671. if test 264 -ne `wc -c <'changes.txt'`; then
  672.     echo shar: \"'changes.txt'\" unpacked with wrong size!
  673. fi
  674. # end of 'changes.txt'
  675. fi
  676. if test -f 'cmd.c' -a "${1}" != "-c" ; then 
  677.   echo shar: Will not clobber existing file \"'cmd.c'\"
  678. else
  679. echo shar: Extracting \"'cmd.c'\" \(3985 characters\)
  680. sed "s/^X//" >'cmd.c' <<'END_OF_FILE'
  681. X#include <stdio.h>
  682. X#include <string.h>
  683. X#include "sysdep.h"
  684. X#include "search.h"
  685. X#include "window.h"
  686. X#include "file.h"
  687. X#include "keym.h"
  688. X#include "externs.h"
  689. X
  690. X/* returns zero if not quit */
  691. X  
  692. int do_extended_key()
  693. X{
  694. X    char ch;
  695. X    static int next = 1;
  696. X    int quit = 0, n;
  697. X    unsigned char *save;
  698. X    
  699. X    select_minibuffer();  putc(':',stdout); fflush(stdout);
  700. X    ch = getkey();
  701. X    putc(ch,stdout); fflush(stdout);
  702. X    if (ch == 'n')
  703. X      {
  704. X          if (!NUM_FILES)
  705. X            {
  706. X                message("File ring is empty.",1);
  707. X            }
  708. X          quit = next_file(&next);
  709. X          if (next == -1) quit = 1;
  710. X      }
  711. X    else if ((ch == 'c') || (ch == 'C'))   /* toggle case sensitive search */
  712. X      {
  713. X          CASE_SENSITIVE = !CASE_SENSITIVE;
  714. X          if (CASE_SENSITIVE)
  715. X            message("Searches now respect case.",0);
  716. X          else
  717. X            message("Searches nolonger respect case.",0);
  718. X      }
  719. X    else if ((ch == 'D') && MOST_D_OPT) /* delete file */
  720. X      {
  721. X          /* notice the missing D. */
  722. X          fprintf(stdout,"elete %s? [n]:", BUF->file);
  723. X          fflush(stdout);
  724. X          ch = getkey();
  725. X          if (ch == 'y')
  726. X            {
  727. X                if (!sys_delete_file(BUF->file))
  728. X                  message("File could not be deleted.",1);
  729. X                else
  730. X                  message("File deleted.",0);
  731. X            }
  732. X          else
  733. X            message("File not deleted.",0);
  734. X      }
  735. X    else if (ch == 'o')
  736. X      {
  737. X          fputs("\rToggle option: b d t v w",stdout); fflush(stdout);
  738. X          ch = getkey();
  739. X          if ((ch == 'd') || (ch == 'w') || (ch == 'b') || (ch == 't') || (ch == 'v') || (ch == 's'))
  740. X            {
  741. X                if (ch == 'b')
  742. X                  {
  743. X                      MOST_B_OPT = !MOST_B_OPT;
  744. X                      NUM_LINES = count_lines(BEG,EOB);
  745. X                  }
  746. X                else if (ch == 'd')
  747. X                  {
  748. X                      if (DIGIT_ARG == NULL)
  749. X                        {
  750. X                            message("Selective Display off.",0);
  751. X                            n = 0;
  752. X                        }
  753. X                      else n = abs( *DIGIT_ARG );
  754. X                      if (MOST_S_OPT != n)
  755. X                        {
  756. X                            MOST_S_OPT = n;
  757. X                            NUM_LINES = count_lines(BEG,EOB);
  758. X                        }
  759. X                  }
  760. X                else if ((ch == 's') && !MOST_B_OPT)
  761. X                  {
  762. X                      SQUEEZE_LINES = !SQUEEZE_LINES;
  763. X                      NUM_LINES = count_lines(BEG,EOB);
  764. X                  }
  765. X                else if (ch == 'w')
  766. X                  {
  767. X                      MOST_W_OPT = !MOST_W_OPT;
  768. X                      NUM_LINES = count_lines(BEG,EOB);
  769. X                  }
  770. X                else if (ch == 'v') MOST_V_OPT = !MOST_V_OPT;
  771. X                else if (ch == 't') MOST_T_OPT = !MOST_T_OPT;
  772. X
  773. X                if (!NUM_LINES) NUM_LINES = 1;
  774. X                
  775. X                save_win_flags(WIN);
  776. X                save = C_POS;
  777. X                C_POS = BEG;
  778. X                C_LINE = 1;
  779. X                C_LINE = what_line(save);
  780. X                C_POS = save;
  781. X                WIN->beg_line = C_LINE;
  782. X                delete_line(1);
  783. X                exit_minibuffer();
  784. X                redraw_window();
  785. X                update_status(0);
  786. X                return(quit);
  787. X            }
  788. X      }
  789. X    else
  790. X      {
  791. X          putc('\007',stdout);
  792. X          delete_line(1);
  793. X      }
  794. X    fflush(stdout);
  795. X    
  796. X    exit_minibuffer();
  797. X    return(quit);
  798. X}
  799. X
  800. X/* returns zero if not quit */
  801. X
  802. int do_extended_cmd()
  803. X{
  804. X    char cmd[80];
  805. X    int quit = 0;
  806. X    cmd[0] = 0;
  807. X    if (!read_from_minibuffer("Cmd:",cmd)) return 0;
  808. X    
  809. X    if (!strcmp(cmd,"cd"))
  810. X      {
  811. X          cd();
  812. X      }
  813. X    else if ((!strncmp(cmd,"quit",strlen(cmd))) || 
  814. X         (!strncmp(cmd,"exit",strlen(cmd))))
  815. X      {
  816. X          quit = -1;
  817. X      }
  818. X    else
  819. X      {
  820. X          strcat(cmd," not understood.");
  821. X          message(cmd,1);
  822. X      }
  823. X    return(quit);
  824. X}
  825. END_OF_FILE
  826. if test 3985 -ne `wc -c <'cmd.c'`; then
  827.     echo shar: \"'cmd.c'\" unpacked with wrong size!
  828. fi
  829. # end of 'cmd.c'
  830. fi
  831. if test -f 'dir.c' -a "${1}" != "-c" ; then 
  832.   echo shar: Will not clobber existing file \"'dir.c'\"
  833. else
  834. echo shar: Extracting \"'dir.c'\" \(2665 characters\)
  835. sed "s/^X//" >'dir.c' <<'END_OF_FILE'
  836. X/* directory functions-- mainly unix stuff, needs work for VMS */
  837. X#ifndef VMS
  838. X#include <sys/types.h>
  839. X#include <sys/dir.h>
  840. X#endif
  841. X
  842. X#include "buffer.h"
  843. X#include "window.h"
  844. X#include "file.h"
  845. X
  846. void get_cdir(char *dir)
  847. X{
  848. X    int i;
  849. X#ifndef VMS
  850. X    getwd(dir);
  851. X    i = strlen(dir); dir[i] = '/'; dir[i] = '\0';
  852. X#else
  853. X    getcwd(dir,80);
  854. X#endif
  855. X}
  856. X
  857. X
  858. X#ifndef VMS
  859. X/* This is a cheap routine-- should be replaced!!!! */
  860. bubble_sort()
  861. X{
  862. X    unsigned char *this, *next, *save;
  863. X    char tmp[80], *t;
  864. X    int change;
  865. X    
  866. X    change = 1;
  867. X    while(change)
  868. X      {
  869. X          next = this = BEG;
  870. X          while((next < EOB) && (*next++ != 0));
  871. X          if (next == EOB) return;
  872. X          change = 0;
  873. X          while(next < EOB)
  874. X            {
  875. X                if (strcmp((char *)this,(char *) next) > 0)
  876. X                  {
  877. X                      change = 1;
  878. X                      strcpy(tmp,(char *) this);
  879. X                      t = tmp;
  880. X                      while(*next != 0) *this++ = *next++;
  881. X                      *this++ = 0;
  882. X                      save = this;
  883. X                      /* now next points at a null */
  884. X                      next++;
  885. X                      while(*t != 0) *this++ = *t++;
  886. X                      *this = 0;
  887. X                      this = save;
  888. X                  }
  889. X                else
  890. X                  {
  891. X                      this = next;
  892. X                      while(next < EOB && *next++ != 0);
  893. X                  }
  894. X            }
  895. X      }
  896. X}
  897. X
  898. void get_dir(char *dir)
  899. X{
  900. X    DIR *dirp;
  901. X    struct direct *dp;
  902. X    char *p;
  903. X    unsigned char *pos;
  904. X    int dsize, len, size = 4096, i;
  905. X    
  906. X    if (*dir == 0)
  907. X      dirp = opendir(".");
  908. X    else
  909. X      dirp = opendir(dir);
  910. X
  911. X    if (dirp == NULL)
  912. X      {
  913. X          message("Unable to open directory.",1);
  914. X          return;
  915. X      }
  916. X    
  917. X          
  918. X    BEG = (unsigned char *) malloc(size);
  919. X    strcpy(BUF->file,dir);
  920. X    pos = BEG;
  921. X    dsize = size;
  922. X    EOB = BEG + size;
  923. X    
  924. X    for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
  925. X      {
  926. X          p = dp->d_name;
  927. X          len = dp->d_namlen;
  928. X          if (pos + len >= EOB - 1)
  929. X            {
  930. X                size += dsize;
  931. X                BEG = (unsigned char *) realloc(BEG,size);
  932. X                
  933. X                EOB = BEG + size;
  934. X                pos = EOB - dsize;
  935. X            }
  936. X          strcpy(pos,p);
  937. X          pos += len;
  938. X          /*           *pos++ = '\n'; */
  939. X          *pos++ = '\0';
  940. X      }
  941. X
  942. X    BUF->end = EOB = pos;
  943. X    BUF->beg = BEG;
  944. X    closedir(dirp);
  945. X    bubble_sort();
  946. X    i = 0;
  947. X    for (pos = BEG; pos < EOB; pos++)
  948. X      if (*pos == '\0')
  949. X        {
  950. X            if (i = !i, i) *pos = '\t'; else *pos = '\n';
  951. X        }
  952. X    
  953. X}
  954. X#endif
  955. X
  956. END_OF_FILE
  957. if test 2665 -ne `wc -c <'dir.c'`; then
  958.     echo shar: \"'dir.c'\" unpacked with wrong size!
  959. fi
  960. # end of 'dir.c'
  961. fi
  962. if test -f 'display.c' -a "${1}" != "-c" ; then 
  963.   echo shar: Will not clobber existing file \"'display.c'\"
  964. else
  965. echo shar: Extracting \"'display.c'\" \(7762 characters\)
  966. sed "s/^X//" >'display.c' <<'END_OF_FILE'
  967. X#include <stdio.h>
  968. X#include "buffer.h"  
  969. X#include "display.h"  
  970. X#include "sysdep.h"  
  971. X
  972. int SCREEN_WIDTH = 80;
  973. int SCREEN_WIDTH_M1 = 79;
  974. int SCREEN_HEIGHT = 24;
  975. int SCREEN_ROWS = 23; /* height - 1 */
  976. X
  977. extern int MOST_L_OPT;
  978. X
  979. char *INS_MODE_STR = "\033[4h";   /* ins mode (im) */
  980. char *EINS_MODE_STR = "\033[4l";  /* end ins mode (ei) */
  981. char *SCROLL_R_STR = "\033[%d;%dr"; /* scroll region */
  982. char *CLS_STR = "\033[2J\033[H";  /* cl termcap STR  for ansi terminals */
  983. char *CLR_BOS_STR = "\033[1J";   /* erase to beg of screen */
  984. char *REV_INDEX_STR = "\033M";     /* sr termcap string */
  985. char *REV_VID_STR = "\033[7m";    /* mr,so termcap string */
  986. char *BOLD_VID_STR = "\033[1m";    /**/
  987. char *UNDL_VID_STR = "\033[4m";    /**/
  988. char *NORM_VID_STR = "\033[m";   /* me,se termcap string */
  989. char *DEL_BOL_STR = "\033[1K\r";  /* cb termcap entry */
  990. char *DEL_EOL_STR = "\033[K"; 
  991. char *HOME_CURS_STR = "\033[H";   /* ho termcap string */
  992. char *DEL_LINE_STR = "\r\033[K";   /* dl termcap string except cursor at bol */
  993. char *DEL_CHAR_STR = "\033[P";   /* dc */
  994. char *DEL_N_LINES_STR = "\033[%dM";  /* DL */
  995. char *ADD_N_LINES_STR = "\033[%dL";  /* AL */
  996. char *CURS_F_STR = "\033[%dC";    /* RI termcap string */
  997. char *CURS_B_STR = "\033[%dD";    /* RI termcap string */
  998. char *CURS_U_STR = "\033[%dA";    /* RI termcap string */
  999. char *CURS_D_STR = "\033[%dB";    /* RI termcap string */
  1000. X/* cm string has %i%d since termcap numbers columns from 0 */
  1001. X/* char *CURS_POS_STR = "\033[%d;%df";  ansi-- hor and vert pos */
  1002. char *CURS_POS_STR = "\033[%d;%dH";   /* cm termcap string */
  1003. X
  1004. X
  1005. void set_scroll_region(int r1, int r2)
  1006. X{
  1007. X    fprintf(stdout,SCROLL_R_STR,r1,r2);
  1008. X}
  1009. X
  1010. void goto_rc(int r, int c)
  1011. X{
  1012. X    fprintf(stdout,CURS_POS_STR,r,c);
  1013. X}
  1014. void curs_bol()
  1015. X{
  1016. X    fputc('\015',stdout);
  1017. X}
  1018. X
  1019. void cursor_forward(int n)
  1020. X{
  1021. X    fprintf(stdout,CURS_F_STR,n);
  1022. X}
  1023. X
  1024. void cursor_backward(int n)
  1025. X{
  1026. X    fprintf(stdout,CURS_B_STR,n);
  1027. X}
  1028. X
  1029. void cursor_up(int n)
  1030. X{
  1031. X    fprintf(stdout,CURS_U_STR,n);
  1032. X}
  1033. X
  1034. void cursor_down(int n)
  1035. X{
  1036. X    fprintf(stdout,CURS_D_STR,n);
  1037. X}
  1038. X
  1039. void begin_insert()
  1040. X{
  1041. X    fputs(INS_MODE_STR,stdout);
  1042. X}
  1043. X
  1044. void end_insert()
  1045. X{
  1046. X    fputs(EINS_MODE_STR,stdout);
  1047. X}
  1048. X
  1049. void delete_char()
  1050. X{
  1051. X    fputs(DEL_CHAR_STR,stdout);
  1052. X}
  1053. X
  1054. void delete_line(int n)
  1055. X{
  1056. X      fprintf(stdout,DEL_LINE_STR);
  1057. X}
  1058. X
  1059. void delete_nlines(int n)
  1060. X{
  1061. X    if (n) fprintf(stdout,DEL_N_LINES_STR,n);
  1062. X}
  1063. X
  1064. void clr_bos()   /* delete to beg of screen */
  1065. X{
  1066. X    fputs(CLR_BOS_STR,stdout);
  1067. X}
  1068. X
  1069. void set_attribute(int attr)
  1070. X{
  1071. X    fprintf(stdout,"\033[%dm",attr);
  1072. X}
  1073. X
  1074. void cls()
  1075. X{
  1076. X    fputs(CLS_STR,stdout);
  1077. X}
  1078. X
  1079. void reverse_index(int n)
  1080. X{
  1081. X    while(n--)
  1082. X      fputs(REV_INDEX_STR,stdout);
  1083. X}
  1084. X
  1085. X/* assumes both old and new are the same length */
  1086. smart_puts(char *new,char *old,FILE *fp)
  1087. X{
  1088. X    char out[250], ch, ch1;
  1089. X    int ii,max_len,i,mark;
  1090. X
  1091. X    i = 0;
  1092. X    ii = 0;
  1093. X    while(ch = *new++, ch1 = *old++, (ch == ch1) && (ch != '\0')) i++;
  1094. X    if (ch == '\0') return;
  1095. X
  1096. X    max_len = strlen(CURS_F_STR);
  1097. X    if (i) fprintf(fp, CURS_F_STR, i);
  1098. X
  1099. X    while(1)
  1100. X      {
  1101. X          i = 1; ii = 0;
  1102. X          out[ii++] = ch;
  1103. X          while (ch = *new++, ch1 = *old++, ch != ch1 && ch != '\0') out[ii++] = ch;
  1104. X          mark = ii;
  1105. X          out[ii++] = ch;
  1106. X          while (ch = *new++, ch1 = *old++, ch == ch1 && ch != '\0')
  1107. X            {
  1108. X                i++;
  1109. X                out[ii++] = ch;
  1110. X            }
  1111. X          out[ii] = '\0';
  1112. X          if (ii > max_len)
  1113. X            {
  1114. X                out[mark] = '\0';
  1115. X                fputs(out,fp);
  1116. X                if (ch == '\0') return;
  1117. X                if (i) fprintf(fp, CURS_F_STR, i);
  1118. X            }
  1119. X          else
  1120. X            {
  1121. X                fputs(out,fp);
  1122. X                if (ch == '\0') return;
  1123. X            }          
  1124. X      }    
  1125. X}    
  1126. X    
  1127. X
  1128. X#ifndef VMS
  1129. X/*  This routine may be problematic when there are more windows than
  1130. X    the new screen size can support.  Until I think of what to do,
  1131. X    I  have not touched this routine. */
  1132. void resize_display()
  1133. X{
  1134. X    char c;
  1135. X
  1136. X    get_term_dimensions(&SCREEN_WIDTH, &SCREEN_HEIGHT);
  1137. X    if (SCREEN_WIDTH == 0) SCREEN_WIDTH = 80;
  1138. X    if (SCREEN_HEIGHT == 0) SCREEN_HEIGHT = 24;
  1139. X    SCREEN_ROWS = SCREEN_HEIGHT - 1;
  1140. X    SCREEN_WIDTH_M1 = SCREEN_WIDTH - 1;
  1141. X    c = 'R';   /* force a redraw of screen */
  1142. X    ioctl(0,TIOCSTI,&c);
  1143. X}
  1144. X#endif
  1145. X
  1146. void get_terminfo()
  1147. X{
  1148. X
  1149. X#ifndef VMS
  1150. X    (void) signal(SIGWINCH,resize_display); 
  1151. X#endif
  1152. X    
  1153. X    get_term_dimensions(&SCREEN_WIDTH, &SCREEN_HEIGHT); 
  1154. X    if (SCREEN_WIDTH == 0) SCREEN_WIDTH = 80;
  1155. X    if (SCREEN_HEIGHT == 0) SCREEN_HEIGHT = 24;
  1156. X    SCREEN_ROWS = SCREEN_HEIGHT - 1;
  1157. X    SCREEN_WIDTH_M1 = SCREEN_WIDTH - 1;
  1158. X
  1159. X    /* someday I will add something here for non-dec terminals
  1160. X       perhaps a 'most-cap' terminal entry :^)
  1161. X
  1162. X       For the time being we do it in this rather primitive manner */
  1163. X
  1164. X    if (MOST_L_OPT)   /* dumb terminal */
  1165. X      {
  1166. X          CLS_STR = "\014";  /* a formfeed */
  1167. X          REV_INDEX_STR = "";
  1168. X          REV_VID_STR = "";
  1169. X          BOLD_VID_STR = "";    /**/
  1170. X          UNDL_VID_STR = "";    /**/
  1171. X          NORM_VID_STR = "";
  1172. X          HOME_CURS_STR = "";
  1173. X          DEL_LINE_STR = "";
  1174. X          DEL_BOL_STR = DEL_LINE_STR;  /* for our purposes */
  1175. X          CURS_F_STR = "";
  1176. X          CURS_POS_STR = "";
  1177. X      }
  1178. X    
  1179. X}
  1180. X
  1181. X
  1182. X
  1183. void narrow_width()
  1184. X{
  1185. X    fputs("\033[?3l",stdout);
  1186. X}
  1187. X
  1188. void wide_width()
  1189. X{
  1190. X    fputs("\033[?3h",stdout);
  1191. X}
  1192. X
  1193. X
  1194. void set_width(int width, int redraw)
  1195. X{
  1196. X#ifdef VMS
  1197. X    short fd;
  1198. X    int status;
  1199. X    iosb iostatus;
  1200. X    static termchar tc; /* Terminal characteristics   */
  1201. X    $DESCRIPTOR( devnam, "SYS$ERROR");
  1202. X#else
  1203. X    struct winsize wind_struct;
  1204. X#endif      
  1205. X
  1206. X    /* Switching physical terminal to narrow/wide mode.*/
  1207. X          
  1208. X    if(width<=80)
  1209. X      {
  1210. X          width = 80;
  1211. X          narrow_width();
  1212. X      }
  1213. X    else
  1214. X      {
  1215. X          width = 132;
  1216. X          wide_width();
  1217. X      }
  1218. X    SCREEN_WIDTH = width;
  1219. X    SCREEN_WIDTH_M1 = width - 1;
  1220. X    
  1221. X#ifdef VMS
  1222. X    /* Assign input to a channel */
  1223. X    status = sys$assign(&devnam, &fd, 0, 0);
  1224. X    if ((status & 1) == 0)
  1225. X      exit(status);
  1226. X    /* Get current terminal characteristics */
  1227. X    status = sys$qiow(          /* Queue and wait   */
  1228. X                      0,        /* Wait on event flag zero  */
  1229. X                      fd,       /* Channel to input terminal  */
  1230. X                      IO$_SENSEMODE, /* Get current characteristic */
  1231. X                      &iostatus, /* Status after operation */
  1232. X                      0, 0,     /* No AST service   */
  1233. X                      &tc,      /* Terminal characteristics buf */
  1234. X                      sizeof(tc), /* Size of the buffer   */
  1235. X                      0, 0, 0, 0); /* P3-P6 unused     */
  1236. X    
  1237. X    /*set terminal characteristics */
  1238. X    tc.t_width=width;
  1239. X    status = sys$qiow(           /* Queue and wait   */
  1240. X                      0,           /* Wait on event flag zero  */
  1241. X                      fd,           /* Channel to input terminal  */
  1242. X                      IO$_SETMODE,   /* Get current characteristic */
  1243. X                      &iostatus,       /* Status after operation */
  1244. X                      0, 0,            /* No AST service   */
  1245. X                      &tc,             /* Terminal characteristics buf */
  1246. X                      sizeof(tc),      /* Size of the buffer   */
  1247. X                      0, 0, 0, 0);     /* P3-P6 unused     */
  1248. X    
  1249. X    if( (sys$dassgn(fd)  & 1)==0)
  1250. X      exit(status);
  1251. X
  1252. X    /* here we redraw the screen, on unix, we assume that the terminal
  1253. X       driver sends the appropriate signal that most catches to redraw so we
  1254. X       do not redraw because it is likely that screen will be redrawn twice */
  1255. X
  1256. X    if (redraw) redraw_display();
  1257. X#else
  1258. X    /* this may need work on other unix-- works for sun4 */
  1259. X    ioctl(2,TIOCGWINSZ,&wind_struct);
  1260. X    wind_struct.ws_col = width;
  1261. X    ioctl(2,TIOCSWINSZ,&wind_struct);
  1262. X    
  1263. X#endif /* VMS */
  1264. X}
  1265. X
  1266. X
  1267. END_OF_FILE
  1268. if test 7762 -ne `wc -c <'display.c'`; then
  1269.     echo shar: \"'display.c'\" unpacked with wrong size!
  1270. fi
  1271. # end of 'display.c'
  1272. fi
  1273. if test -f 'display.h' -a "${1}" != "-c" ; then 
  1274.   echo shar: Will not clobber existing file \"'display.h'\"
  1275. else
  1276. echo shar: Extracting \"'display.h'\" \(688 characters\)
  1277. sed "s/^X//" >'display.h' <<'END_OF_FILE'
  1278. X  
  1279. X#ifndef VMS
  1280. X#include <signal.h>
  1281. X#endif
  1282. X
  1283. extern int SCREEN_WIDTH;
  1284. extern int SCREEN_WIDTH_M1;
  1285. extern  int SCREEN_HEIGHT;
  1286. extern  int SCREEN_ROWS; /* height - 1 */
  1287. X
  1288. extern void set_scroll_region(int, int);
  1289. extern void goto_rc(int, int);
  1290. extern void curs_bol();
  1291. extern void cursor_forward(int);
  1292. extern void cursor_backward(int);
  1293. extern void cursor_up(int);
  1294. extern void cursor_down(int);
  1295. extern void begin_insert();
  1296. extern void end_insert();
  1297. extern void delete_char();
  1298. extern void delete_line(int);
  1299. extern void set_attribute(int);
  1300. extern void cls();
  1301. extern void reverse_index();
  1302. extern void set_width(int, int);
  1303. extern void get_terminfo();
  1304. X#ifndef VMS
  1305. extern void resize_display();
  1306. X#endif
  1307. END_OF_FILE
  1308. if test 688 -ne `wc -c <'display.h'`; then
  1309.     echo shar: \"'display.h'\" unpacked with wrong size!
  1310. fi
  1311. # end of 'display.h'
  1312. fi
  1313. if test -f 'edit.c' -a "${1}" != "-c" ; then 
  1314.   echo shar: Will not clobber existing file \"'edit.c'\"
  1315. else
  1316. echo shar: Extracting \"'edit.c'\" \(1935 characters\)
  1317. sed "s/^X//" >'edit.c' <<'END_OF_FILE'
  1318. X/* editor functions */
  1319. X
  1320. X#include "externs.h"
  1321. X#include "window.h"
  1322. X#include "sysdep.h"
  1323. X
  1324. X#ifdef VMS
  1325. X
  1326. int call_edt_tpu(char *file, int line, int what)
  1327. X{
  1328. X    char the_file[100];
  1329. X    extern void edt$edit();
  1330. X    extern void tpu$tpu();
  1331. X    struct dsc$descriptor_s  file_desc;
  1332. X    if (what == 1)  /* tpu */
  1333. X      strcpy(the_file,"TPU ");
  1334. X    else
  1335. X      the_file[0] = '\0';
  1336. X    
  1337. X    strcat(the_file,file);
  1338. X    
  1339. X    file_desc.dsc$w_length = strlen(the_file);
  1340. X    file_desc.dsc$a_pointer = the_file;
  1341. X    file_desc.dsc$b_class = DSC$K_CLASS_S; /* scalar, string type */
  1342. X    file_desc.dsc$b_dtype = DSC$K_DTYPE_T; /* ascii string */
  1343. X
  1344. X    if (what == 1)
  1345. X      tpu$tpu(&file_desc);
  1346. X    else
  1347. X      edt$edit(&file_desc);
  1348. X
  1349. X    return(1);
  1350. X}
  1351. X
  1352. int call_emacs(char *file, int line)
  1353. X{
  1354. X    int status;
  1355. X    char lstr[40];
  1356. X    (void) sprintf(lstr,"%d",line);
  1357. X    define_logical_name("EMACS_FILE_LINE",lstr);
  1358. X    define_logical_name("EMACS_FILE_NAME",file);
  1359. X    status = do_emacs_command();
  1360. X    delete_logical_name("EMACS_FILE_NAME");
  1361. X    delete_logical_name("EMACS_FILE_LINE");
  1362. X    return(status);
  1363. X}
  1364. X
  1365. void edit_cmd()
  1366. X{
  1367. X    char *editor, file[80], *strp;
  1368. X    int status;
  1369. X    
  1370. X    if ((editor = getenv("MOST_EDITOR")) == NULL)  editor = "EDT";
  1371. X          
  1372. X    strcpy(file,WIN->buf->file);
  1373. X    strp = file;
  1374. X    /*  lose the version number */
  1375. X    while((*strp != '\0') && (*strp != ';')) strp++;
  1376. X    *strp = '\0';
  1377. X    
  1378. X    reset_tty();
  1379. X    reset_display();
  1380. X    fflush(stdout);
  1381. X    
  1382. X    if (!strcmp(editor,"EMACS"))
  1383. X      {
  1384. X          status = call_emacs(file,C_LINE);
  1385. X      }
  1386. X    else if (!strcmp(editor,"EDT"))
  1387. X      {
  1388. X          status = call_edt_tpu(file,C_LINE,0);
  1389. X      }
  1390. X    else if (!strcmp(editor,"TPU"))
  1391. X      {
  1392. X          status = call_edt_tpu(file,C_LINE,1);
  1393. X      }
  1394. X    else message("Unknown editor.",1);
  1395. X    if (status)
  1396. X      {
  1397. X          redraw_display();
  1398. X      }
  1399. X    else message("Unable to edit.",1);
  1400. X}
  1401. X    
  1402. X#else
  1403. X
  1404. void edit_cmd()
  1405. X  {
  1406. X      ;
  1407. X  }
  1408. X
  1409. X#endif
  1410. END_OF_FILE
  1411. if test 1935 -ne `wc -c <'edit.c'`; then
  1412.     echo shar: \"'edit.c'\" unpacked with wrong size!
  1413. fi
  1414. # end of 'edit.c'
  1415. fi
  1416. if test -f 'externs.h' -a "${1}" != "-c" ; then 
  1417.   echo shar: Will not clobber existing file \"'externs.h'\"
  1418. else
  1419. echo shar: Extracting \"'externs.h'\" \(987 characters\)
  1420. sed "s/^X//" >'externs.h' <<'END_OF_FILE'
  1421. extern char SEARCH_STR[80];
  1422. extern int SEARCH_DIRECTION;
  1423. extern int STARTING_LINE;   /*  begin at this line upon startup of most */
  1424. extern int CASE_SENSITIVE;
  1425. X
  1426. extern int NUM_LINES;
  1427. extern int ACTUAL_LINES;
  1428. extern int CURS_ROW;
  1429. extern int CURS_COL;
  1430. extern unsigned char *CURS_POS;
  1431. X
  1432. extern int SQUEEZE_LINES;          /* switch parameters */
  1433. extern int MOST_L_OPT;             /* use ^L (formfeed) to clear screen */
  1434. extern int MOST_V_OPT;             /* display control chars */
  1435. extern int MOST_B_OPT;             /* display Binary File */
  1436. extern int MOST_T_OPT;             /* display tab as ^I-- valid only with V option */
  1437. extern int MOST_W_OPT;             /* wrap lines if true */
  1438. extern int MOST_S_OPT;             /* selective display */
  1439. extern int MOST_K_OPT;             /* Kanji option */
  1440. X
  1441. extern int MOST_D_OPT;             /* delete file mode  (see ':D')  */
  1442. X
  1443. X#define _MOST_V_OPT  1
  1444. X#define _MOST_T_OPT  2
  1445. X#define _MOST_B_OPT  4
  1446. X#define _MOST_SQ_OPT 8
  1447. X#define _MOST_W_OPT 16
  1448. END_OF_FILE
  1449. if test 987 -ne `wc -c <'externs.h'`; then
  1450.     echo shar: \"'externs.h'\" unpacked with wrong size!
  1451. fi
  1452. # end of 'externs.h'
  1453. fi
  1454. if test -f 'file.c' -a "${1}" != "-c" ; then 
  1455.   echo shar: Will not clobber existing file \"'file.c'\"
  1456. else
  1457. echo shar: Extracting \"'file.c'\" \(7456 characters\)
  1458. sed "s/^X//" >'file.c' <<'END_OF_FILE'
  1459. X#include <stdio.h>
  1460. X#include <string.h>
  1461. X#ifndef VMS
  1462. X#include <fcntl.h>
  1463. X#include <sys/types.h>
  1464. X#include <sys/stat.h>
  1465. X#else
  1466. X#include <unixio.h>
  1467. X#include <types.h>
  1468. X#include <stat.h>
  1469. X#endif
  1470. X
  1471. X#ifndef O_RDONLY
  1472. X#define O_RDONLY 0
  1473. X#endif
  1474. X  
  1475. X#include "externs.h"
  1476. X#include "file.h"
  1477. X#include "keym.h"  
  1478. X#include "buffer.h"
  1479. X#include "window.h"
  1480. X
  1481. char *FILE_RING[500];
  1482. char C_DIR[80];                 /* current working dir */
  1483. int NUM_FILES;
  1484. X
  1485. extern int SCREEN_WIDTH;
  1486. X
  1487. int insert_file(char *file)
  1488. X{
  1489. X    struct stat st;
  1490. X    int i,n,size, fd, dsize;
  1491. X    unsigned char *pos;
  1492. X
  1493. X    if (file[0] == '\0')        /* assume stdin */
  1494. X      {
  1495. X          fd = 0;
  1496. X          strcpy(BUF->file,"(Standard Input)");
  1497. X      }
  1498. X    else
  1499. X      {
  1500. X          stat(file, &st);
  1501. X          if (st.st_mode & S_IFDIR)  /* S_IFDIR = 0040000 */
  1502. X            {
  1503. X#ifndef VMS
  1504. X                get_dir(file);
  1505. X#endif                
  1506. X                return(1);
  1507. X            }
  1508. X          size = st.st_size;
  1509. X#ifdef VMS          
  1510. X          /* VMS share options (shr=put) suggested by Henk D. Davids <hdavids@mswe.dnet.ms.philips.nl> */
  1511. X          /* VMS share options (shr=upi,get,put) suggested by Mark Pizzolato <mark@infocomm.com> */
  1512. X          fd = open(file,O_RDONLY,"ctx=rec","mbf=8","mbc=16","rop=RAH","shr=upi,get,put");
  1513. X#else
  1514. X          fd = open(file,O_RDONLY);
  1515. X#endif          
  1516. X      }
  1517. X    
  1518. X    
  1519. X    if (fd >= 0)
  1520. X      {
  1521. X          if (!fd) size = 16384;
  1522. X          BEG = BUF->beg = (unsigned char *) malloc(size);
  1523. X          n = 0;
  1524. X          pos = BUF->beg;
  1525. X          dsize = size;
  1526. X          while ((i = read(fd, (char *) pos, size - n)) > 0 )
  1527. X            {
  1528. X                n += i;
  1529. X                if ((fd == 0) && (size == n))
  1530. X                  {
  1531. X                      size += dsize;
  1532. X                      BEG = (unsigned char *) realloc(BEG,size * sizeof(char));
  1533. X                      pos = BEG + n;
  1534. X                  }
  1535. X                else pos += i;
  1536. X            }
  1537. X          BUF->end = pos;
  1538. X          BUF->beg = BEG;
  1539. X          close(fd);
  1540. X          return (1);
  1541. X      }
  1542. X    return(0);
  1543. X}
  1544. X
  1545. int find_file(char *file)
  1546. X{
  1547. X    Buffer *new_buf, *old_buf;
  1548. X    int a,n;
  1549. X    unsigned char *pos;
  1550. X    
  1551. X    
  1552. X    new_buf = create_buffer(file);
  1553. X    old_buf = switch_to_buffer(new_buf);
  1554. X    
  1555. X    if (insert_file(file) == 0)
  1556. X      {
  1557. X          message("File could not be opened.",1);
  1558. X          BUF->beg = (unsigned char *) "File could Not be opened.";
  1559. X          BUF->end = BUF->beg + strlen((char *) BUF->beg);
  1560. X      }
  1561. X    BEG = BUF->beg;
  1562. X    EOB = BUF->end;
  1563. X    if (!MOST_B_OPT && !MOST_K_OPT)
  1564. X      for (pos = BEG; (pos < (BEG + 32)) && (pos < EOB); pos++)
  1565. X      {
  1566. X          if ((*pos == 0) || (*pos > 127)) MOST_B_OPT = 1;
  1567. X      }
  1568. X    
  1569. X    n = count_lines(BEG,EOB);
  1570. X    
  1571. X    NUM_LINES = n;
  1572. X    C_POS = BEG;
  1573. X    C_LINE = 1;
  1574. X    COLUMN = 1;
  1575. X    return(1);
  1576. X}
  1577. X
  1578. X/* if the file is visible in a window, move to the window and return 1
  1579. X   else return 0 */
  1580. int file_visible(char *file)
  1581. X{
  1582. X    Window *w;
  1583. X    w = WIN;
  1584. X    WIN = TOP_WIN;
  1585. X    do
  1586. X      {
  1587. X          if (!strcmp(WIN->buf->file,file))
  1588. X            {
  1589. X                set_window(WIN);
  1590. X                return(1);
  1591. X            }
  1592. X          WIN = WIN->next;
  1593. X      }
  1594. X    while (WIN != TOP_WIN);
  1595. X    WIN = w;
  1596. X    return(0);
  1597. X}
  1598. X
  1599. X
  1600. void find_file_in_window(char *file)
  1601. X{
  1602. X    if (file_visible(file)) return;
  1603. X    
  1604. X    if (-1 == access(file,0))        /* does it exist? */
  1605. X      message("File not found.",1);
  1606. X    else if (-1 == access(file,4))   /* can we read it? */
  1607. X      message("File exists but not readable.",1);
  1608. X    else 
  1609. X      {
  1610. X          free_window_buffer();
  1611. X          (void) find_file(file);
  1612. X
  1613. X          window_buffer();
  1614. X          CURS_ROW = WIN->curs_line = 1;
  1615. X          CURS_POS = WIN->curs_pos = C_POS;
  1616. X          CURS_COL = WIN->curs_col = 1;
  1617. X
  1618. X          redraw_window();
  1619. X          update_status(0);
  1620. X      }
  1621. X}
  1622. X
  1623. X
  1624. X
  1625. int next_file(int *j)
  1626. X{
  1627. X    char mbuf[132], ch, *curr_file;
  1628. X    int i;
  1629. X    
  1630. X    mbuf[0] = '\0';
  1631. X    select_minibuffer();
  1632. X    delete_line(1);
  1633. X
  1634. X    for (i = 0; i < SCREEN_WIDTH; i++) MINI_BUF[i] = ' ';
  1635. X
  1636. X    if (*j >= NUM_FILES) *j = 0;
  1637. X    curr_file = FILE_RING[*j];
  1638. X    strcat(mbuf,"Next file: ");
  1639. X    strcat(mbuf, curr_file);
  1640. X    fputs(mbuf,stdout);
  1641. X    fputc('\r',stdout);
  1642. X    fflush(stdout);
  1643. X    while(ch = mbuf[i], ch != '\0') i++;
  1644. X    while(i < SCREEN_WIDTH) mbuf[i++] = ' ';
  1645. X    mbuf[i] = '\0';
  1646. X    strcpy((char *) MINI_BUF,mbuf);
  1647. X    while (1)
  1648. X      {
  1649. X          ch = getkey();
  1650. X          if (ch != '\033') break;
  1651. X          if (ch = getkey(), (ch != 'O') && (ch != '[')) continue;
  1652. X          if (ch = getkey(), (ch != 'A') && (ch != 'B')) continue;
  1653. X          
  1654. X          if (ch == 'B')
  1655. X            {
  1656. X                if (*j == 0) *j = NUM_FILES;
  1657. X                (*j)--;
  1658. X            }
  1659. X          else  /* ch == 'A' */
  1660. X            {
  1661. X                (*j)++;
  1662. X                if (*j == NUM_FILES) *j = 0;
  1663. X            }
  1664. X          curr_file = FILE_RING[*j];
  1665. X          mbuf[0] = '\0';
  1666. X          strcat(mbuf,"Next file: ");
  1667. X          strcat(mbuf, curr_file);
  1668. X          i = 0;
  1669. X          while(ch = mbuf[i], ch != '\0') i++;
  1670. X          while(i < SCREEN_WIDTH) mbuf[i++] = ' ';
  1671. X          mbuf[i] = '\0';
  1672. X          
  1673. X          smart_puts(mbuf,MINI_BUF,stdout);
  1674. X          fputc('\r',stdout);
  1675. X          strcpy((char *) MINI_BUF,mbuf);
  1676. X          fflush(stdout);
  1677. X      }
  1678. X    delete_line(1);
  1679. X    exit_minibuffer();
  1680. X    MINI_BUF[0] = 0;
  1681. X    (*j)++;
  1682. X    if ((ch == 'Q') || (ch == 'q')) return(-1);
  1683. X    
  1684. X    find_file_in_window(curr_file);
  1685. X    return(0);
  1686. X}
  1687. X
  1688. X/* extracts directory from file string, returns false if no dir */
  1689. int head(char *file, char *dir)
  1690. X{
  1691. X    int n;
  1692. X    (void) strcpy(dir,file);
  1693. X    n = strlen(file) - 1;
  1694. X#ifdef VMS    
  1695. X    while((n > -1) && (file[n] != ']') && (file[n] != ':')) n--;
  1696. X#else    
  1697. X    while((n > -1) && file[n] != '/') n--;
  1698. X#endif
  1699. X    n++;
  1700. X    dir[n] = '\0';
  1701. X    return(n);
  1702. X}
  1703. X
  1704. X/* returns a pointer to the tail of file */
  1705. int tail(char *filed, char **filep)
  1706. X{
  1707. X    int n;
  1708. X    n = strlen(filed) - 1;
  1709. X#ifdef VMS    
  1710. X    while((n > -1) && (filed[n] != ']') || (filed[n] != ':')) n--;
  1711. X#else    
  1712. X    while((n > -1) && filed[n] != '/') n--;
  1713. X#endif
  1714. X    n++;
  1715. X    *filep = (filed + n);
  1716. X    return(n);
  1717. X}
  1718. X
  1719. X/* assume path is big enough to hold new expanded version */
  1720. int expand_path(char *path)
  1721. X{
  1722. X    int n;
  1723. X    /* really cheat here-- let system do it.  The path must exist!! */
  1724. X    if (chdir(path))
  1725. X      {
  1726. X          message(path,1);
  1727. X          return(0);
  1728. X      }
  1729. X    else
  1730. X      {
  1731. X          get_cdir(path);
  1732. X          chdir(C_DIR);
  1733. X#ifndef VMS
  1734. X          n = strlen(path);
  1735. X          if (path[n-1] == '/') return(1);
  1736. X          path[n++] = '/'; path[n] = 0;
  1737. X#endif
  1738. X      }
  1739. X    return(1);
  1740. X}
  1741. X
  1742. X
  1743. X
  1744. void cd()
  1745. X{
  1746. X    char tmp_dir[80];
  1747. X    int n;
  1748. X    
  1749. X    strcpy(tmp_dir,C_DIR);
  1750. X    if (read_from_minibuffer("cd: ",C_DIR) == -1) return;
  1751. X    if (!chdir(C_DIR))
  1752. X      {
  1753. X          get_cdir(C_DIR);         /* expands ../ etc... */
  1754. X          n = strlen(C_DIR);
  1755. X#ifndef VMS
  1756. X          if (C_DIR[n-1] == '/') return;
  1757. X          C_DIR[n++] = '/'; C_DIR[n] = 0;
  1758. X#endif          
  1759. X          return;
  1760. X      }
  1761. X    strcpy(C_DIR,tmp_dir);
  1762. X    chdir(C_DIR);
  1763. X    message("Unable to change directory.",1);
  1764. X}
  1765. X
  1766. void user_get_file()
  1767. X{
  1768. X    char path[80], file[80], *name;
  1769. X    
  1770. X    if (!head(WIN->buf->file,file))
  1771. X      strcpy(file,C_DIR);
  1772. X
  1773. X    if (read_from_minibuffer("Find File: ",file) == -1) return;
  1774. X
  1775. X    if (head(file,path))
  1776. X      {
  1777. X          expand_path(path);
  1778. X          tail(file,&name);
  1779. X          strcat(path,name);
  1780. X          name = path;
  1781. X      }
  1782. X    else name = file;
  1783. X    find_file_in_window(name);
  1784. X}
  1785. X
  1786. END_OF_FILE
  1787. if test 7456 -ne `wc -c <'file.c'`; then
  1788.     echo shar: \"'file.c'\" unpacked with wrong size!
  1789. fi
  1790. # end of 'file.c'
  1791. fi
  1792. if test -f 'file.h' -a "${1}" != "-c" ; then 
  1793.   echo shar: Will not clobber existing file \"'file.h'\"
  1794. else
  1795. echo shar: Extracting \"'file.h'\" \(177 characters\)
  1796. sed "s/^X//" >'file.h' <<'END_OF_FILE'
  1797. extern int insert_file(char *);
  1798. extern int find_file(char *);
  1799. extern void find_file_in_window(char *);
  1800. extern char *FILE_RING[500];
  1801. extern char C_DIR[80];
  1802. extern int NUM_FILES;
  1803. END_OF_FILE
  1804. if test 177 -ne `wc -c <'file.h'`; then
  1805.     echo shar: \"'file.h'\" unpacked with wrong size!
  1806. fi
  1807. # end of 'file.h'
  1808. fi
  1809. if test -f 'help.c' -a "${1}" != "-c" ; then 
  1810.   echo shar: Will not clobber existing file \"'help.c'\"
  1811. else
  1812. echo shar: Extracting \"'help.c'\" \(3219 characters\)
  1813. sed "s/^X//" >'help.c' <<'END_OF_FILE'
  1814. X#include <stdio.h>
  1815. X#ifdef VMS
  1816. X#include <stat.h>
  1817. X#else
  1818. X#include <sys/types.h>
  1819. X#include <sys/stat.h>
  1820. X#endif
  1821. X#include "window.h"
  1822. X#include "file.h"  
  1823. X#include "display.h"  
  1824. X#include "line.h"
  1825. X#include "most.h"  
  1826. X  
  1827. X#ifndef MOST_HELP_USE_DOC
  1828. X/* This section provided by Mats Akerberg (mats@efd.lth.se) */
  1829. X  
  1830. static char *help[] = {
  1831. X"SPACE,^D,D,d        *Scroll down one Screen.",
  1832. X"RETURN, DOWN        *Move forward one line.",
  1833. X"u,U,^U, DELETE      *Move Up one screen.",
  1834. X"UP                  *Move up one line.",
  1835. X"R, r, ^R             Redraw Screen.",
  1836. X"T,t                  Top of File.",
  1837. X"B,b                  Bottom of file.",
  1838. X"RIGHT                Scroll Screen Left (to view lines right of right margin)",
  1839. X"LEFT                 Scroll Screen Right (To view lines left of left margin)",
  1840. X"F,f,/               *Find forward",
  1841. X"?                   *Find Backward",
  1842. X"n,N                 *Find next in current search direction.",
  1843. X"J,j,g,G              Goto line.",
  1844. X"%                    Goto percent.",
  1845. X"q,Q                  Quit MOST.",
  1846. X":N,:n                Quit this file and view next.",
  1847. X" *Note:  This command may be repeated `n' times By entering a number then",
  1848. X"        the command key, e.g.,  '5 SPACE' moves 5 screens forward.",
  1849. NULL };
  1850. X
  1851. void do_help_command()
  1852. X{
  1853. X    int i,ct;
  1854. X    char *beg, *end;
  1855. X    char line[80];
  1856. X    char attr[80];
  1857. X    
  1858. X    i = 1;
  1859. X    ct = 0;
  1860. X    set_scroll_region(1,SCREEN_HEIGHT);
  1861. X    cls();
  1862. X    while( i<SCREEN_ROWS)
  1863. X      {
  1864. X          if( help[ct]!=NULL)
  1865. X            {
  1866. X                beg = help[ct];
  1867. X                end = (help[ct] + strlen(help[ct++]));
  1868. X                analyse_line((unsigned char *) beg, (unsigned char *) end, line, attr);
  1869. X                output(line,end - beg,attr,'$');
  1870. X                fputc('\n',stdout);
  1871. X                i++;
  1872. X            }
  1873. X          else
  1874. X            {
  1875. X        set_attribute(7);
  1876. X                fputs("Press any key to continue.",stdout);
  1877. X        set_attribute(0);
  1878. X                fflush(stdout);
  1879. X        getkey();
  1880. X                redraw_display();
  1881. X        return;
  1882. X            }
  1883. X          fflush(stdout);
  1884. X      }
  1885. X}
  1886. X
  1887. X#else
  1888. void do_help_command()
  1889. X{
  1890. X    int fd, n_lines,s_lines,v_opt,b_opt,t_opt, sd, a_lines, fsize, c_line;
  1891. X    char *helpfile ,*buf_name,f_name[80],s_str[80];
  1892. X    unsigned char *beg, *c_pos, *e_pos;
  1893. X    extern char *getenv(char *);
  1894. X
  1895. X    buf_name = "*help*";
  1896. X    helpfile = getenv("MOST_HELP");
  1897. X    if (helpfile == NULL)
  1898. X      {
  1899. X      static char tempname[L_tmpnam];
  1900. X      struct stat statb;
  1901. X
  1902. X      head(MOST_PROGRAM, tempname);
  1903. X      strcat(tempname, "most.doc");
  1904. X      if (0 == stat(tempname, &statb))
  1905. X        {
  1906. X            helpfile = tempname;
  1907. X        }
  1908. X      }
  1909. X    if (helpfile != NULL)
  1910. X      {
  1911. X          if (file_visible(buf_name)) return;
  1912. X          if (!split_window())
  1913. X            {
  1914. X                message("Two many windows.",1);
  1915. X                return;
  1916. X            }
  1917. X          update_status(1);  /* create status line of prev. window */
  1918. X          other_window(1);
  1919. X          (void) find_file(helpfile);
  1920. X          strcpy(BUF->file,buf_name);
  1921. X          window_buffer();
  1922. X          redraw_window();
  1923. X          update_status(1);
  1924. X      }
  1925. X    else
  1926. X      {
  1927. X          message("You must set the environment variable 'MOST_HELP' to point to the help file.",1);
  1928. X      }
  1929. X}       
  1930. X#endif
  1931. END_OF_FILE
  1932. if test 3219 -ne `wc -c <'help.c'`; then
  1933.     echo shar: \"'help.c'\" unpacked with wrong size!
  1934. fi
  1935. # end of 'help.c'
  1936. fi
  1937. if test -f 'keym.h' -a "${1}" != "-c" ; then 
  1938.   echo shar: Will not clobber existing file \"'keym.h'\"
  1939. else
  1940. echo shar: Extracting \"'keym.h'\" \(1444 characters\)
  1941. sed "s/^X//" >'keym.h' <<'END_OF_FILE'
  1942. X  
  1943. extern void beep_cmd();
  1944. extern void ctrl_x_map_cmd();
  1945. extern void ctrl_k_map_cmd();
  1946. extern void ctrl_w_map_cmd();
  1947. extern void pf1_map_cmd();
  1948. extern void pf1_esc_map_cmd();
  1949. extern void dec_extended_map_cmd();
  1950. extern void esc_map_cmd();
  1951. extern void page_down_cmd();
  1952. extern void search_cmd();
  1953. extern void help_cmd();
  1954. extern void next_line_cmd();
  1955. extern void previous_line_cmd();
  1956. extern void extended_cmd_cmd();
  1957. extern void redraw_cmd();
  1958. extern void goto_line_cmd();
  1959. extern void time_cmd();
  1960. extern void page_up_cmd();
  1961. extern void page_left_cmd();
  1962. extern void page_right_cmd();
  1963. extern void sys_spawn_cmd();
  1964. extern void set_mark_cmd();
  1965. extern void top_of_buffer_cmd();
  1966. extern void goto_mark_cmd();
  1967. extern void extended_key_cmd();
  1968. extern void search_back_cmd();
  1969. extern void find_next_cmd();
  1970. extern void end_of_buffer_cmd();
  1971. extern void exit_cmd();
  1972. extern void one_window_cmd();
  1973. extern void two_window_cmd();
  1974. extern void del_window_cmd();
  1975. extern void other_window_cmd();
  1976. extern void O_map_cmd();
  1977. extern void find_file_cmd();
  1978. extern void digit_arg_cmd();
  1979. extern void edit_cmd();
  1980. extern void toggle_width_cmd();
  1981. extern void goto_percent_cmd();
  1982. extern void edt_page_cmd();
  1983. extern void edt_forward_cmd();
  1984. extern void edt_back_cmd();
  1985. extern void edt_line_cmd();
  1986. extern void edt_find_cmd();
  1987. extern void edt_find_next_cmd();
  1988. X
  1989. extern int *DIGIT_ARG;
  1990. X
  1991. X#ifdef VMS
  1992. X#ifndef isdigit
  1993. X#define isdigit(x) \
  1994. X      (((x >= '0') && (x <= '9')) ? 1 : 0)
  1995. X#endif
  1996. X#endif
  1997. X
  1998. END_OF_FILE
  1999. if test 1444 -ne `wc -c <'keym.h'`; then
  2000.     echo shar: \"'keym.h'\" unpacked with wrong size!
  2001. fi
  2002. # end of 'keym.h'
  2003. fi
  2004. if test -f 'line.c' -a "${1}" != "-c" ; then 
  2005.   echo shar: Will not clobber existing file \"'line.c'\"
  2006. else
  2007. echo shar: Extracting \"'line.c'\" \(10420 characters\)
  2008. sed "s/^X//" >'line.c' <<'END_OF_FILE'
  2009. X#include <stdio.h>
  2010. X#include "buffer.h"
  2011. X#include "externs.h"
  2012. X#include "display.h"
  2013. X#include "line.h"
  2014. X  
  2015. extern int COLUMN;
  2016. X
  2017. X#define MAX_LINE_LEN 500
  2018. int MOST_S_OPT = 0;
  2019. X/* take 16 binary characters and put them in displayable form */
  2020. int ascii_format_line(char *buff, char *str)
  2021. X{
  2022. X    int i,ii,j,k,ch,di,flag;
  2023. X    char num_str[4];
  2024. X
  2025. X    ii = 0;
  2026. X    di = 40;
  2027. X    flag = 1;
  2028. X
  2029. X    for (i = 35;i<=di;i++) str[i] = ' ';  /* a gap */
  2030. X    
  2031. X    for (j = 0; j < 4; j++)
  2032. X      {
  2033. X          
  2034. X          for (k = 0; k < 4; k++)
  2035. X            {
  2036. X                i = 4 * j + k;
  2037. X                ch = buff[i];
  2038. X                if (MOST_V_OPT)
  2039. X                  {
  2040. X                      if (((ch < 32) && (ch >= 0)) || (ch == 127))
  2041. X                        {
  2042. X                            str[ii++] = '^';
  2043. X                            if (ch == 127)
  2044. X                              str[ii++] = '?';
  2045. X                            else
  2046. X                              str[ii++] = ch + 'A' - 1;
  2047. X                            str[i + di] = '.';
  2048. X                        }
  2049. X                      else if (ch < 0)
  2050. X                        {
  2051. X                            ch = ch + 256; 
  2052. X                            sprintf(num_str,"%02X", ch);
  2053. X                            str[ii++] = num_str[0];
  2054. X                            str[ii++] = num_str[1];
  2055. X                            str[i + di] = '.';
  2056. X                        }
  2057. X                      else
  2058. X                        {
  2059. X                            str[ii++] = ' ';
  2060. X                            str[ii++] = ch;
  2061. X                            str[i + di] = ch;
  2062. X                        }
  2063. X                  }
  2064. X                else
  2065. X                  {
  2066. X                      if (ch < 32)
  2067. X                        {
  2068. X                            if (ch < 0) ch = ch + 256;
  2069. X                            str[i + di] = '.';
  2070. X                        }
  2071. X                      else str[i+di] = ch;
  2072. X                      
  2073. X                      sprintf(num_str,"%02X", ch);
  2074. X                      str[ii++] = num_str[0];
  2075. X                      str[ii++] = num_str[1];
  2076. X                  }
  2077. X                
  2078. X            } /* k */
  2079. X          str[ii++] = ' ';
  2080. X      }
  2081. X    di += 16;
  2082. X    str[di] = '\0';
  2083. X    return(di);
  2084. X}
  2085. X    
  2086. X
  2087. int analyse_line(unsigned char *beg, unsigned char *end, char *out, char *attributes)
  2088. X{
  2089. X    int test, ii, fold, ii_max, j, ok;
  2090. X    unsigned char ch,attr;
  2091. X
  2092. X    test = 0;
  2093. X    ii = 0;
  2094. X    ii_max = 0;
  2095. X    fold = 0;
  2096. X    while(ch = *beg, (beg <= end) && (ch != '\n') && (ch != '\0'))
  2097. X      {
  2098. X          beg++;
  2099. X          if (ii > ii_max) fold = 0;  /* beyond previous high */
  2100. X          attr = ' ';
  2101. X          if (!MOST_V_OPT && ch == '\015')                   /* ^M */
  2102. X            {
  2103. X                if (beg <= end)
  2104. X                  {
  2105. X                      fold = 1;
  2106. X                      if (ii > ii_max) ii_max = ii - 1; /* ^M contributes nil */
  2107. X                      ii = 0;
  2108. X                  }
  2109. X            }
  2110. X          else if (!MOST_V_OPT && ch == '\b')
  2111. X            {
  2112. X                test = 1;
  2113. X                ii--;
  2114. X            }
  2115. X          else if (test || fold)
  2116. X            {
  2117. X                test = 0;
  2118. X                if (ch == out[ii])
  2119. X                  attr = 'b';
  2120. X                else if (out[ii] == '_')
  2121. X                  attr = 'u';
  2122. X
  2123. X                if (fold && ch == ' ')
  2124. X                  ii++;
  2125. X                else
  2126. X                  {
  2127. X                      attributes[ii] = attr;
  2128. X                      out[ii++] = ch;
  2129. X                  }
  2130. X                
  2131. X            }
  2132. X          else if (!MOST_T_OPT && ch == '\t')
  2133. X            {
  2134. X                j = 8 * (ii/8 + 1) - ii;  /* 8 column tabs */
  2135. X                while(j--)
  2136. X                  {
  2137. X                      out[ii] = ' ';
  2138. X                      attributes[ii++] = attr;
  2139. X                  }
  2140. X            }
  2141. X          else
  2142. X            {
  2143. X                out[ii] = ch;
  2144. X                attributes[ii++] = attr;
  2145. X            }
  2146. X      }
  2147. X    if (fold) ii = ii_max + 1;
  2148. X    if ((beg > end) && MOST_S_OPT && !MOST_W_OPT)
  2149. X      {
  2150. X          ok = 1;
  2151. X          if (*beg == '\n') beg++;
  2152. X          while ((*beg <= ' ') && ok)
  2153. X            {
  2154. X                if (*beg != '\n') beg++;
  2155. X                if (beg >= EOB) break;
  2156. X                if ((*beg == '\n') || (apparant_distance(beg) >= MOST_S_OPT))
  2157. X                  {
  2158. X                      ok = 0;
  2159. X                  }
  2160. X            }
  2161. X          if (!ok)
  2162. X            {
  2163. X                ok = 3;
  2164. X                while(ok--)
  2165. X                  {
  2166. X                      out[ii] = '.'; 
  2167. X                      attributes[ii++] = ' ';
  2168. X                  }
  2169. X            }
  2170. X          
  2171. X      } /* MOST_S_OPT */
  2172. X    out[ii] = '\0';
  2173. X    return(ii);
  2174. X}
  2175. X
  2176. X
  2177. void output(char *line, int len, char *attr, char d_char)
  2178. X{
  2179. X    int
  2180. X      i,ii,k, bold,b_len,n_len, s_len, u_len, work_len, j, mark, ok, quit,
  2181. X      count, max_col, save, dollar;
  2182. X    char ch, at, out[500], *n_str, *b_str, *s_str, *u_str, work[20];
  2183. X
  2184. X    b_str = "\033[1m"; n_str = "\033[0m"; s_str = "\033[%dC"; u_str = "\033[4m";
  2185. X    b_len = strlen(b_str);
  2186. X    n_len = strlen(n_str);
  2187. X    u_len = strlen(u_str);
  2188. X    s_len = strlen(s_str);
  2189. X    i = 0;
  2190. X    ii = 0;
  2191. X    bold = 0;
  2192. X    quit = 0;
  2193. X    ok = 0;  /* 1 if ok to start filling the out line */
  2194. X    max_col = COLUMN + SCREEN_WIDTH - 1;
  2195. X    count = 0;
  2196. X    dollar = 0;
  2197. X    while (ch = line[i], (i <= len) && ch != '\0' && ch != '\n' && !quit)
  2198. X      {
  2199. X          count++;
  2200. X          if (MOST_V_OPT && ((ch < ' ') || (ch > 126))) count++;
  2201. X          
  2202. X          if (count >= COLUMN) ok = 1;
  2203. X          if (count > max_col) break;
  2204. X          
  2205. X          if (!MOST_V_OPT)
  2206. X            {
  2207. X                at = attr[i];
  2208. X                if ((at != ' ') && !bold)
  2209. X                  {
  2210. X                      bold = 1;
  2211. X                      /* u and b have same length */
  2212. X                      if (ok) for (j = 0; j < b_len; j++)
  2213. X                        {
  2214. X                            if (at == 'b') out[ii++] = b_str[j];
  2215. X                            else out[ii++] = u_str[j];
  2216. X                        }
  2217. X                      
  2218. X                  }
  2219. X                else if ((at == ' ') && bold)
  2220. X                  {
  2221. X                      bold = 0;
  2222. X                      if (ok) for (j = 0; j < n_len; j++) out[ii++] = n_str[j];
  2223. X                  }
  2224. X            }
  2225. X          
  2226. X          if (ch == ' ')
  2227. X            {
  2228. X                j = 0;
  2229. X                mark = ii;
  2230. X                /* we always make this loop once */
  2231. X                while ((i <= len) && (line[i++] == ' '))
  2232. X                  {
  2233. X                      j++;
  2234. X                      if (ok) out[ii++] = ' ';
  2235. X                  }
  2236. X                if (i > len) quit = 1;
  2237. X                i = i - 2;
  2238. X                save = count;
  2239. X                count += j - 1;  /* counted one at top of while */
  2240. X
  2241. X                if (!ok)
  2242. X                  {
  2243. X                      if (count >= COLUMN)
  2244. X                        {
  2245. X                            ok = 1;
  2246. X                            j = count - COLUMN + 1;
  2247. X                            k = j;
  2248. X                            while (k--) out[ii++] = ' ';
  2249. X                        }
  2250. X                  }
  2251. X                
  2252. X                if (count >= max_col)
  2253. X                  {
  2254. X                      quit = 1;
  2255. X                      j = max_col - save;
  2256. X                  }
  2257. X                
  2258. X                if (ok && (j > s_len)) 
  2259. X                  {
  2260. X                      ii = mark;
  2261. X                      sprintf(work,s_str,j);
  2262. X                      work_len = strlen(work);
  2263. X                      for (j = 0; j < work_len; j++) out[ii++] = work[j];
  2264. X                      if (count >= max_col) dollar = ii++;
  2265. X                  }
  2266. X                else if (count >= max_col)
  2267. X                  {
  2268. X                      dollar = mark + j;
  2269. X                  }
  2270. X                
  2271. X            }
  2272. X          else if (ok && ((ch == '\014') || ((ch < ' ') && MOST_V_OPT)))
  2273. X            {
  2274. X                out[ii++] = '^';
  2275. X                out[ii++] = ch + 'A' - 1;
  2276. X            }
  2277. X          else if (ok) 
  2278. X            {
  2279. X                out[ii++] = ch;
  2280. X            }
  2281. X          
  2282. X          i++;
  2283. X      }
  2284. X    if (dollar) out[ii = dollar, ii++] = d_char;
  2285. X    else if (ok && count >= max_col) out[ii - 1] = d_char;
  2286. X    out[ii] = '\0';
  2287. X    if (ii) fputs(out,stdout);
  2288. X    
  2289. X    if (ok && bold) fputs(n_str,stdout);
  2290. X}
  2291. X
  2292. X
  2293. void display_line()
  2294. X{
  2295. X    unsigned char *beg, *end;
  2296. X    int i, len, v, t;
  2297. X    char buff[16];
  2298. X    char the_line[MAX_LINE_LEN],  *p, the_attr[MAX_LINE_LEN], *line,*attr, ch;
  2299. X    line = the_line;
  2300. X    attr = the_attr;
  2301. X    /* This needs fixed for files with really big lines */
  2302. X    if (!MOST_B_OPT)
  2303. X      {
  2304. X          if(extract_line(&beg, &end) && MOST_W_OPT) ch = '\\'; else ch = '$';
  2305. X          
  2306. X          len = end - beg + 1;
  2307. X          if (len > MAX_LINE_LEN)
  2308. X            {
  2309. X                v = MOST_V_OPT;
  2310. X                t = MOST_T_OPT;
  2311. X                MOST_V_OPT = 1;
  2312. X                MOST_T_OPT = 1;
  2313. X                line = (char *) beg;
  2314. X            }
  2315. X          else len = analyse_line(beg, end, line, attr);
  2316. X      }
  2317. X    else
  2318. X      {
  2319. X          ch = '$';
  2320. X          i = 0;
  2321. X          beg = C_POS;
  2322. X          end = C_POS + 16;
  2323. X          if (end > EOB) end = EOB;
  2324. X          while(beg < end) buff[i++] = (char) *beg++;
  2325. X          while(i < 15) buff[i++] = 0;
  2326. X          len = ascii_format_line(buff,the_line);
  2327. X          i = 0; while(i<80) attr[i++] = ' ';
  2328. X      }
  2329. X    
  2330. X    
  2331. X    output(line,len,attr, ch);
  2332. X    if (len > MAX_LINE_LEN)
  2333. X      {
  2334. X          MOST_V_OPT = v;
  2335. X          MOST_T_OPT = t;
  2336. X      }
  2337. X}
  2338. X
  2339. X
  2340. X/* given a position in a line, return apparant distance from bol
  2341. X   expanding tabs, etc... up to pos */
  2342. int apparant_distance(unsigned char *pos)
  2343. X{
  2344. X    int i;
  2345. X    unsigned char *cur_pos, *save_pos, ch;
  2346. X    cur_pos = C_POS;
  2347. X    save_pos = pos;
  2348. X    C_POS = pos;
  2349. X    pos = beg_of_line();
  2350. X    C_POS = cur_pos;
  2351. X
  2352. X    i = 1;
  2353. X    while(ch = *pos, pos++ < save_pos)
  2354. X      {
  2355. X          if (!MOST_V_OPT && ch == '\b')
  2356. X            {
  2357. X                if (i > 1) i--;
  2358. X            }
  2359. X          else if (!MOST_V_OPT && ch == '\015') /* ^M */
  2360. X            {
  2361. X                if (i != 1) i = 1;
  2362. X            }
  2363. X          else if (!MOST_T_OPT && ch == '\t')
  2364. X            {
  2365. X                i = 8 * ((i - 1)/8 + 1) + 1;  /* 8 column tabs */
  2366. X            }
  2367. X          else if (ch < ' ' || ch > 126)
  2368. X            {
  2369. X                if (ch == '\012' || MOST_V_OPT)  /* ^L */
  2370. X                  {
  2371. X                      i += 2;
  2372. X                  }             /* otherwise they have no width */
  2373. X            }
  2374. X          else i++;
  2375. X      }
  2376. X    return (i);
  2377. X}
  2378. X
  2379. X
  2380. X
  2381. END_OF_FILE
  2382. if test 10420 -ne `wc -c <'line.c'`; then
  2383.     echo shar: \"'line.c'\" unpacked with wrong size!
  2384. fi
  2385. # end of 'line.c'
  2386. fi
  2387. if test -f 'line.h' -a "${1}" != "-c" ; then 
  2388.   echo shar: Will not clobber existing file \"'line.h'\"
  2389. else
  2390. echo shar: Extracting \"'line.h'\" \(337 characters\)
  2391. sed "s/^X//" >'line.h' <<'END_OF_FILE'
  2392. X#ifndef _DAVIS_LINE_H_
  2393. X#define _DAVIS_LINE_H_
  2394. extern int ascii_format_line(char *, char *);
  2395. extern void expand_tabs(char *, char *);
  2396. extern int analyse_line(unsigned char *, unsigned char *, char *, char *);
  2397. extern void output(char *, int, char *, char);
  2398. extern void display_line();
  2399. extern int apparant_distance(unsigned char *);
  2400. X#endif
  2401. END_OF_FILE
  2402. if test 337 -ne `wc -c <'line.h'`; then
  2403.     echo shar: \"'line.h'\" unpacked with wrong size!
  2404. fi
  2405. # end of 'line.h'
  2406. fi
  2407. if test -f 'main.c' -a "${1}" != "-c" ; then 
  2408.   echo shar: Will not clobber existing file \"'main.c'\"
  2409. else
  2410. echo shar: Extracting \"'main.c'\" \(10070 characters\)
  2411. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  2412. X#define __MOST_VERSION__ "3.2"
  2413. X#define __MOST_USAGE__ "most [-bstvw] [+line] [+/string] [+[C][D]] filename"
  2414. X/*
  2415. X               Most ---- a more/less paging type program.
  2416. X
  2417. X    Copyright (C) 1991 by John E. Davis. (davis@pacific.ms.ohio-state.edu)
  2418. X
  2419. X                   The following disclaimer from GNU emacs.
  2420. X
  2421. X                                 NO WARRANTY
  2422. X
  2423. X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO
  2424. WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT WHEN
  2425. OTHERWISE STATED IN WRITING, JOHN E. DAVIS AND/OR OTHER PARTIES PROVIDE THIS
  2426. PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  2427. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  2428. XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
  2429. PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE,
  2430. YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  2431. X
  2432. X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL JOHN E. DAVIS, AND/OR ANY
  2433. OTHER PARTY WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW,
  2434. BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  2435. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2436. INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
  2437. RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE
  2438. PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS PROGRAM, EVEN IF YOU HAVE
  2439. BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER
  2440. PARTY.
  2441. X
  2442. X                        GENERAL PUBLIC LICENSE TO COPY
  2443. X
  2444. X  1. You may copy and distribute verbatim copies of this source file as you
  2445. receive it, in any medium, provided that you conspicuously and appropriately
  2446. publish on each copy a valid copyright notice "Copyright (C) 1990 John E.
  2447. Davis"; and include following the copyright notice a verbatim copy of the
  2448. above disclaimer of warranty and of this License.  You may charge a
  2449. distribution fee for the physical act of transferring a copy.
  2450. X
  2451. X  2. You may modify your copy or copies of this source file or
  2452. any portion of it, and copy and distribute such modifications under
  2453. the terms of Paragraph 1 above, provided that you also do the following:
  2454. X
  2455. X    a) cause the modified files to carry prominent notices stating
  2456. X    that you changed the files and the date of any change; and
  2457. X
  2458. X    b) cause the whole of any work that you distribute or publish,
  2459. X    that in whole or in part contains or is a derivative of this
  2460. X    program or any part thereof, to be licensed at no charge to all
  2461. X    third parties on terms identical to those contained in this
  2462. X    License Agreement (except that you may choose to grant more extensive
  2463. X    warranty protection to some or all third parties, at your option).
  2464. X
  2465. X    c) You may charge a distribution fee for the physical act of
  2466. X    transferring a copy, and you may at your option offer warranty
  2467. X    protection in exchange for a fee.
  2468. X
  2469. Mere aggregation of another unrelated program with this program (or its
  2470. derivative) on a volume of a storage or distribution medium does not bring
  2471. the other program under the scope of these terms.
  2472. X
  2473. X  3. You may copy and distribute this program (or a portion or derivative
  2474. of it, under Paragraph 2) in object code or executable form under the terms
  2475. of Paragraphs 1 and 2 above provided that you also do one of the following:
  2476. X
  2477. X    a) accompany it with the complete corresponding machine-readable
  2478. X    source code, which must be distributed under the terms of
  2479. X    Paragraphs 1 and 2 above; or,
  2480. X
  2481. X    b) accompany it with a written offer, valid for at least three
  2482. X    years, to give any third party free (except for a nominal
  2483. X    shipping charge) a complete machine-readable copy of the
  2484. X    corresponding source code, to be distributed under the terms of
  2485. X    Paragraphs 1 and 2 above; or,
  2486. X
  2487. X    c) accompany it with the information you received as to where the
  2488. X    corresponding source code may be obtained.  (This alternative is
  2489. X    allowed only for noncommercial distribution and only if you
  2490. X    received the program in object code or executable form alone.)
  2491. X
  2492. XFor an executable file, complete source code means all the source code for
  2493. all modules it contains; but, as a special exception, it need not include
  2494. source code for modules which are standard libraries that accompany the
  2495. operating system on which the executable file runs.
  2496. X
  2497. X  4. You may not copy, sublicense, distribute or transfer this program
  2498. except as expressly provided under this License Agreement.  Any attempt
  2499. otherwise to copy, sublicense, distribute or transfer this program is void and
  2500. your rights to use the program under this License agreement shall be
  2501. automatically terminated.  However, parties who have received computer
  2502. software programs from you with this License Agreement will not have
  2503. their licenses terminated so long as such parties remain in full compliance.
  2504. X
  2505. In other words, you are welcome to use, share and improve this program.
  2506. You are forbidden to forbid anyone else to use, share and improve
  2507. what you give them.   Help stamp out software-hoarding!  */
  2508. X
  2509. char *MOST_VERSION = __MOST_VERSION__ ;
  2510. X#include <stdio.h>
  2511. X#include "externs.h"
  2512. X#include "window.h"
  2513. X#include "buffer.h"
  2514. X#include "file.h"
  2515. X#include "sysdep.h"
  2516. X#include "most.h"
  2517. X
  2518. int MOST_K_OPT = 0;    /* Display 8 bit unformatted (Kanji) */
  2519. int  CASE_SENSITIVE, STARTING_LINE;
  2520. char SEARCH_STR[80];
  2521. char *MOST_PROGRAM;    /* Program Name (argv[0]) */
  2522. X
  2523. X#ifdef VMS
  2524. X#ifndef isalpha
  2525. X#define isalpha(x) \
  2526. X      (((x >= 'A') && (x <= 'Z'))||((x >= 'a') && (x <= 'z')) ? 1 : 0)
  2527. X#endif
  2528. X#endif
  2529. X
  2530. void do_extended_switches(char *str)
  2531. X{
  2532. X    int i;
  2533. X    char ch,numstr[7];
  2534. X    
  2535. X    i = 0;
  2536. X    ch = *(++str);
  2537. X    if ( ch == '/')
  2538. X      {
  2539. X          strcpy(SEARCH_STR,++str);
  2540. X      }
  2541. X    else if (ch >= '0' && ch <= '9')
  2542. X      {
  2543. X          while (ch >= '0' && ch <= '9')
  2544. X            {
  2545. X                numstr[i++] = ch;
  2546. X                ch = *(++str);
  2547. X            }
  2548. X          numstr[i] = '\0';
  2549. X          (void) sscanf(numstr,"%d",&STARTING_LINE);
  2550. X      }
  2551. X    else if (isalpha(ch))
  2552. X      {
  2553. X          while (isalpha(ch))
  2554. X            {
  2555. X                if ((ch == 'C') || (ch == 'c'))
  2556. X                  CASE_SENSITIVE = 1;
  2557. X                else if ((ch == 'D') || (ch == 'd'))
  2558. X                  MOST_D_OPT = 1;   /* delete file mode */
  2559. X                ch = *(++str);
  2560. X            }
  2561. X      }
  2562. X    
  2563. X    else
  2564. X      {
  2565. X          fprintf(stdout,"switch '+%s' not valid.\n",str);
  2566. X          exit(0);
  2567. X      }
  2568. X}
  2569. X
  2570. X
  2571. X
  2572. void do_switches(char *str)
  2573. X{
  2574. X
  2575. X    while (*str != '\0')
  2576. X      {
  2577. X          switch (*str++)
  2578. X            {
  2579. X              case 'a':
  2580. X              case 'A':
  2581. X                MOST_A_OPT = 1; break;  /* check to see if file is binary */
  2582. X              case 's':
  2583. X              case 'S':
  2584. X                SQUEEZE_LINES = 1; break;
  2585. X              case 'c':
  2586. X              case 'C':
  2587. X                MOST_C_OPT = 1; break;
  2588. X              case 'V':
  2589. X              case 'v':
  2590. X                MOST_V_OPT = 1;  /* verbose-- convert control chars to '^' 'ch' */
  2591. X                break;
  2592. X              case 'W':
  2593. X              case 'w':  MOST_W_OPT = 1; break;
  2594. X              case 'K':
  2595. X              case 'k':  MOST_K_OPT = 1; break;
  2596. X              case 'B':
  2597. X              case 'b':
  2598. X                MOST_B_OPT = 1;  /* Binary display 8 bit */
  2599. X                break;
  2600. X              case 't':
  2601. X              case 'T': /* expand tabs to '^I'; meaningful only with 'v' */
  2602. X                MOST_T_OPT = 1;
  2603. X                break;
  2604. X              case 'L':
  2605. X              case 'l':
  2606. X                MOST_L_OPT = 1;  /* use ^L to clear screen */
  2607. X                break;
  2608. X            }
  2609. X      }
  2610. X}
  2611. X   
  2612. int main(int argc, char *argv[])
  2613. X{
  2614. X    char file[80],ch, *switches,outstr[180], *curr_file,filename[80];
  2615. X    int file_i, quit,i,piped,a_opt, j;
  2616. X    unsigned long context;
  2617. X    extern char *getenv(char *);
  2618. X    extern int isatty(int);
  2619. X    extern void sysinit(void);
  2620. X
  2621. X    MOST_PROGRAM = argv[0];
  2622. X    piped = 0;
  2623. X    switches = getenv("MOST_SWITCHES");
  2624. X    if (switches !=  NULL)  do_switches(switches);
  2625. X          
  2626. X    i = 1;
  2627. X    if (argc > 1)
  2628. X      {
  2629. X          quit = 0;
  2630. X          while ((!quit) && (i < argc))
  2631. X            {
  2632. X                if (argv[i][0] == '-')
  2633. X                  do_switches(argv[i++]);
  2634. X                else if (argv[i][0] == '+')
  2635. X                  do_extended_switches(argv[i++]);
  2636. X                else quit = 1;
  2637. X            }
  2638. X      }
  2639. X
  2640. X    
  2641. X    if (i == argc)
  2642. X      {
  2643. X          if (isatty(0))   /* 1 if stdin is a terminal, 0 otherwise */
  2644. X            {
  2645. X                fprintf(stderr,"MOST(%s) Usage: %s\n",MOST_VERSION,__MOST_USAGE__);
  2646. X                        exit(0);
  2647. X            }
  2648. X          /* assume input is from stdin */
  2649. X          file[0] = '\0';  /* tells most this is stdin */
  2650. X          piped = 1;
  2651. X          MOST_A_OPT = 0;  /* in this version since we cannot do an fseek */
  2652. X      }
  2653. X    else
  2654. X      strcpy(file,argv[i]);
  2655. X
  2656. X    NUM_FILES = 0;
  2657. X    context = 0;
  2658. X
  2659. X    get_terminfo();           /* set up esc sequences etc... */
  2660. X    init_tty(); 
  2661. X    if (MOST_B_OPT) MOST_A_OPT = 0;   /* explicit b overrides a */
  2662. X    a_opt = MOST_A_OPT;
  2663. X
  2664. X    if (!piped)
  2665. X      {
  2666. X          file_i = i;
  2667. X#ifdef VMS
  2668. X          while(i < argc)
  2669. X            {
  2670. X                if (argv[i][0] == '.') strcpy(file,"*"); else *file = 0;
  2671. X                strcat(file,unix2vms(argv[i++]));
  2672. X                while (expand_file_name(file,filename))
  2673. X                  {
  2674. X                      FILE_RING[NUM_FILES] = (char*) malloc(strlen(filename) + 1);
  2675. X                      strcpy(FILE_RING[NUM_FILES++], filename);
  2676. X                  }
  2677. X            }
  2678. X          if (NUM_FILES) strcpy(file,FILE_RING[0]);
  2679. X    
  2680. X#else
  2681. X          j = 0;
  2682. X          NUM_FILES = argc - i;
  2683. X          while (i < argc)
  2684. X            {
  2685. X                FILE_RING[j++] = argv[i++];
  2686. X            }
  2687. X#endif
  2688. X      }
  2689. X
  2690. X    if (NUM_FILES) quit = 0; else quit = 1;
  2691. X    if (!quit || piped) most(file,STARTING_LINE);
  2692. X    if (quit) fprintf(stderr,"File %s not found\n", argv[file_i]);
  2693. X
  2694. X    reset_tty();
  2695. X    reset_display();
  2696. X#ifndef  VMS
  2697. X    fputc('\n',stdout);
  2698. X#endif    
  2699. X    exit(0);
  2700. X    return (0);
  2701. X}
  2702. END_OF_FILE
  2703. if test 10070 -ne `wc -c <'main.c'`; then
  2704.     echo shar: \"'main.c'\" unpacked with wrong size!
  2705. fi
  2706. # end of 'main.c'
  2707. fi
  2708. if test -f 'make.com' -a "${1}" != "-c" ; then 
  2709.   echo shar: Will not clobber existing file \"'make.com'\"
  2710. else
  2711. echo shar: Extracting \"'make.com'\" \(1346 characters\)
  2712. sed "s/^X//" >'make.com' <<'END_OF_FILE'
  2713. X$ files = ""
  2714. X$ files = files + ",main.c" - ".c"
  2715. X$ files = files + ",buffer.c" - ".c"
  2716. X$ files = files + ",file.c" - ".c"
  2717. X$ files = files + ",window.c" - ".c"
  2718. X$ files = files + ",line.c" - ".c"
  2719. X$ files = files + ",display.c" - ".c"
  2720. X$ files = files + ",sysdep.c" - ".c"
  2721. X$ files = files + ",keym.c" - ".c"
  2722. X$ files = files + ",most.c" - ".c"
  2723. X$ files = files + ",search.c" - ".c"
  2724. X$ files = files + ",help.c" - ".c"
  2725. X$ files = files + ",dir.c" - ".c"
  2726. X$ files = files + ",cmd.c" - ".c"
  2727. X$ files = files + ",edit.c" - ".c"
  2728. X$ files = files - ","
  2729. X$!
  2730. X$! if you do not want the doc file used as help, but want a short one page
  2731. X$! help summary then comment out the following line:
  2732. X$ cc := cc/define=MOST_HELP_USE_DOC
  2733. X$!
  2734. X$  if (p1 .eqs. "LINK") then goto do_link
  2735. X$  write sys$output "Compiling..."
  2736. X$  cc 'files'
  2737. X$  do_link:
  2738. X$  write sys$output "Linking..."
  2739. X$  link/exec = most  'files',sys$input/opt
  2740. SYS$LIBRARY:VAXCRTL/SHARE
  2741. X$  write sys$output "Setting up MOST...
  2742. X$  curr_dir = f$environment("DEFAULT")
  2743. X$  most = "$" + curr_dir + "most.exe"
  2744. X$  most :== 'most'
  2745. X$  most_h = curr_dir + "most.doc"
  2746. X$  define MOST_HELP 'most_h'
  2747. X$  type := type
  2748. X$  type sys$input
  2749. X         
  2750. X        MOST is now setup for this login session.  
  2751. X        
  2752. X        Type 'most filename' to view the file 'filename'.
  2753. X        In particular, type 'most most.doc' to read the doc file.
  2754. X
  2755. X$  exit
  2756. END_OF_FILE
  2757. if test 1346 -ne `wc -c <'make.com'`; then
  2758.     echo shar: \"'make.com'\" unpacked with wrong size!
  2759. fi
  2760. # end of 'make.com'
  2761. fi
  2762. if test -f 'makecom.com' -a "${1}" != "-c" ; then 
  2763.   echo shar: Will not clobber existing file \"'makecom.com'\"
  2764. else
  2765. echo shar: Extracting \"'makecom.com'\" \(812 characters\)
  2766. sed "s/^X//" >'makecom.com' <<'END_OF_FILE'
  2767. X$!
  2768. X$! if you do not want the doc file used as help, but want a short one page
  2769. X$! help summary then comment out the following line:
  2770. X$ cc := cc/define=MOST_HELP_USE_DOC
  2771. X$!
  2772. X$  if (p1 .eqs. "LINK") then goto do_link
  2773. X$  write sys$output "Compiling..."
  2774. X$  cc 'files'
  2775. X$  do_link:
  2776. X$  write sys$output "Linking..."
  2777. X$  link/exec = most  'files',sys$input/opt
  2778. SYS$LIBRARY:VAXCRTL/SHARE
  2779. X$  write sys$output "Setting up MOST...
  2780. X$  curr_dir = f$environment("DEFAULT")
  2781. X$  most = "$" + curr_dir + "most.exe"
  2782. X$  most :== 'most'
  2783. X$  most_h = curr_dir + "most.doc"
  2784. X$  define MOST_HELP 'most_h'
  2785. X$  type := type
  2786. X$  type sys$input
  2787. X         
  2788. X        MOST is now setup for this login session.  
  2789. X        
  2790. X        Type 'most filename' to view the file 'filename'.
  2791. X        In particular, type 'most most.doc' to read the doc file.
  2792. X
  2793. X$  exit
  2794. END_OF_FILE
  2795. if test 812 -ne `wc -c <'makecom.com'`; then
  2796.     echo shar: \"'makecom.com'\" unpacked with wrong size!
  2797. fi
  2798. # end of 'makecom.com'
  2799. fi
  2800. if test -f 'makefile' -a "${1}" != "-c" ; then 
  2801.   echo shar: Will not clobber existing file \"'makefile'\"
  2802. else
  2803. echo shar: Extracting \"'makefile'\" \(1227 characters\)
  2804. sed "s/^X//" >'makefile' <<'END_OF_FILE'
  2805. X# if you do not want the foc file used as help, but want a short one page
  2806. X# help summary then comment out the following line:
  2807. HELP = -DMOST_HELP_USE_DOC
  2808. X# and uncomment the next line:
  2809. X#  HELP =
  2810. X
  2811. CFILES = main.c buffer.c file.c window.c line.c display.c \
  2812. X          sysdep.c keym.c most.c search.c help.c dir.c cmd.c edit.c
  2813. OBJS = main.o buffer.o file.o window.o line.o display.o \
  2814. X          sysdep.o keym.o most.o search.o help.o dir.o cmd.o edit.o
  2815. HFILES = buffer.h file.h window.h line.h display.h \
  2816. X          sysdep.h keym.h most.h search.h externs.h
  2817. MISC  = most.1 most.doc make.com aaa_read.me rtl.opt changes.txt makefile\
  2818. X          makecom.com
  2819. X
  2820. CC = cc 
  2821. CFLAGS = -g $(HELP)
  2822. XEXEC = m
  2823. X
  2824. X$(EXEC): $(OBJS)
  2825. X    $(CC) $(CFLAGS) $(OBJS) -o $(EXEC)
  2826. X
  2827. unix:
  2828. X    shar -b $(CFILES) $(HFILES) $(MISC) > most.shar
  2829. X
  2830. most.doc:    most.1
  2831. X        nroff -man $? > $@
  2832. X
  2833. vms:
  2834. X    (echo  "\$$ files = \"\"" ) > make.com
  2835. X    for file in $(CFILES); do\
  2836. X           (echo  "\$$ files = files + \",$$file\" - \".c\"")\
  2837. X                 >> make.com; \
  2838. X    done
  2839. X    (echo  "\$$ files = files - \",\"" ) >> make.com
  2840. X    (cat makecom.com) >> make.com
  2841. X    pack $(CFILES) $(HFILES) $(MISC) -o most.com
  2842. X
  2843. lpr:
  2844. X    for file in $(CFILES) $(HFILES); do\
  2845. X        pprint north $$file -l c -p; \
  2846. X    done
  2847. X
  2848. X
  2849. X
  2850. X
  2851. X
  2852. X
  2853. END_OF_FILE
  2854. if test 1227 -ne `wc -c <'makefile'`; then
  2855.     echo shar: \"'makefile'\" unpacked with wrong size!
  2856. fi
  2857. # end of 'makefile'
  2858. fi
  2859. if test -f 'most.c' -a "${1}" != "-c" ; then 
  2860.   echo shar: Will not clobber existing file \"'most.c'\"
  2861. else
  2862. echo shar: Extracting \"'most.c'\" \(1478 characters\)
  2863. sed "s/^X//" >'most.c' <<'END_OF_FILE'
  2864. X#include <stdio.h>
  2865. X#include "externs.h"
  2866. X#include "window.h"
  2867. X#include "buffer.h"
  2868. X#include "file.h"
  2869. X#include "sysdep.h"
  2870. X#include "keym.h"
  2871. X#include "most.h"
  2872. X#include "search.h"  
  2873. X
  2874. int SQUEEZE_LINES = 0;          /* switch parameters */
  2875. int MOST_A_OPT = 0;             /* automatically choose -b if necessary */
  2876. int MOST_C_OPT = 0;             /* begin pages at top of screen */
  2877. int MOST_V_OPT = 0;             /* display control chars */
  2878. int MOST_B_OPT = 0;             /* display Binary File */
  2879. int MOST_T_OPT = 0;             /* display tab as ^I-- valid only with V option */
  2880. int MOST_D_OPT = 0;             /* delete file mode  (see ':D')  */
  2881. int MOST_L_OPT = 0;             /* use ^L (formfeed) to clear screen */
  2882. X
  2883. void most(char *file, int start)
  2884. X{
  2885. X    char input_s[20],ch,outstr[80], *strp;
  2886. X    int line, update, quit, j, repeat, mark, piped, next, row, col, r;
  2887. X    
  2888. X    init_display();
  2889. X    get_cdir(C_DIR);
  2890. X
  2891. X    row = col = 0;
  2892. X    if (file[0] == '\0') piped = 1; else piped = 0;
  2893. X    
  2894. X    find_file(file);
  2895. X    goto_line(start);
  2896. X    CURS_POS = C_POS;
  2897. X    if (*SEARCH_STR != '\0' && (row = search(C_POS,1,&col), row > 0))
  2898. X      {
  2899. X          goto_line(row);
  2900. X      }
  2901. X    else
  2902. X      {
  2903. X          row = C_LINE;
  2904. X          col = 1;
  2905. X      }
  2906. X    
  2907. X    window_buffer();
  2908. X    CURS_ROW = WIN->curs_line = row - C_LINE + 1;
  2909. X    WIN->curs_pos = CURS_POS;
  2910. X    CURS_COL = WIN->curs_col = col;
  2911. X    redraw_window();
  2912. X    update_status(1);
  2913. X
  2914. X    while (1)
  2915. X      {
  2916. X          execute_key();
  2917. X      } 
  2918. X}
  2919. END_OF_FILE
  2920. if test 1478 -ne `wc -c <'most.c'`; then
  2921.     echo shar: \"'most.c'\" unpacked with wrong size!
  2922. fi
  2923. # end of 'most.c'
  2924. fi
  2925. if test -f 'most.h' -a "${1}" != "-c" ; then 
  2926.   echo shar: Will not clobber existing file \"'most.h'\"
  2927. else
  2928. echo shar: Extracting \"'most.h'\" \(655 characters\)
  2929. sed "s/^X//" >'most.h' <<'END_OF_FILE'
  2930. extern int SQUEEZE_LINES;          /* switch parameters */
  2931. extern int MOST_A_OPT;             /* automatically choose -b if necessary */
  2932. extern int MOST_C_OPT;             /* begin pages at top of screen */
  2933. extern int MOST_V_OPT;             /* display control chars */
  2934. extern int MOST_B_OPT;             /* display Binary File */
  2935. extern int MOST_T_OPT;             /* display tab as ^I-- valid only with V option */
  2936. extern int MOST_D_OPT;             /* delete file mode  (see ':D')  */
  2937. extern int MOST_L_OPT;             /* use ^L (formfeed) to clear screen */
  2938. X
  2939. extern char *MOST_PROGRAM;       /* Program Name (argv[0]) */
  2940. extern void most( char *, int);
  2941. END_OF_FILE
  2942. if test 655 -ne `wc -c <'most.h'`; then
  2943.     echo shar: \"'most.h'\" unpacked with wrong size!
  2944. fi
  2945. # end of 'most.h'
  2946. fi
  2947. if test -f 'rtl.opt' -a "${1}" != "-c" ; then 
  2948.   echo shar: Will not clobber existing file \"'rtl.opt'\"
  2949. else
  2950. echo shar: Extracting \"'rtl.opt'\" \(26 characters\)
  2951. sed "s/^X//" >'rtl.opt' <<'END_OF_FILE'
  2952. SYS$LIBRARY:VAXCRTL/SHARE
  2953. END_OF_FILE
  2954. if test 26 -ne `wc -c <'rtl.opt'`; then
  2955.     echo shar: \"'rtl.opt'\" unpacked with wrong size!
  2956. fi
  2957. # end of 'rtl.opt'
  2958. fi
  2959. if test -f 'search.c' -a "${1}" != "-c" ; then 
  2960.   echo shar: Will not clobber existing file \"'search.c'\"
  2961. else
  2962. echo shar: Extracting \"'search.c'\" \(5318 characters\)
  2963. sed "s/^X//" >'search.c' <<'END_OF_FILE'
  2964. X#include "most.h"
  2965. X#include "externs.h"
  2966. X#include "buffer.h"
  2967. X#include "line.h"
  2968. X
  2969. int CASE_SENSITIVE = 0;
  2970. char SEARCH_STR[80];
  2971. int SEARCH_DIR = 1;
  2972. X
  2973. X#define upcase(ch) ((!CASE_SENSITIVE && (ch <= 'z') && (ch >= 'a')) ? ch &= 0xDF : ch)
  2974. X
  2975. X/* This routine returns the 1 + position of first match of key in str.
  2976. X   key is modified to match the case of str. */
  2977. X/* We should try to optimize this routine */
  2978. X/* searches from beg up to but not including end */
  2979. unsigned char *forw_search_region(unsigned char *beg,unsigned char *end, unsigned char *key)
  2980. X{
  2981. X    char ch, ch2,char1,work[80];
  2982. X    unsigned char *pos;
  2983. X    int key_len,j, str_len;
  2984. X
  2985. X    if (CASE_SENSITIVE)
  2986. X      {
  2987. X          strcpy(work,key);
  2988. X          key_len = strlen(key);
  2989. X      }
  2990. X    else
  2991. X      {
  2992. X          /* upcase key */
  2993. X          key_len = 0;
  2994. X          while (ch = key[key_len],ch != '\0')
  2995. X            {
  2996. X                ch = upcase(ch);
  2997. X                work[key_len++] = ch;        /* null char is ok */
  2998. X            }
  2999. X      }
  3000. X    
  3001. X    str_len = (int) (end - beg);
  3002. X    if (str_len < key_len) return (EOB);
  3003. X    str_len = str_len - key_len; /* effective length */
  3004. X    end -= key_len;
  3005. X          
  3006. X    char1 = work[0];
  3007. X    
  3008. X    while(1)
  3009. X      {
  3010. X          while (ch = *beg, ch = upcase(ch), ch != char1)
  3011. X            {
  3012. X                if (beg > end) return(EOB);
  3013. X                beg++;
  3014. X            }
  3015. X          beg++;
  3016. X          /* so we have a position of possible match */
  3017. X
  3018. X          j = 1;
  3019. X          pos = beg;  /* save this position so we start from here again */
  3020. X          while(ch = *beg++, ch = upcase(ch),
  3021. X                ch2 = work[j++], (ch == ch2) && (j <= key_len));
  3022. X
  3023. X          if (j > key_len)
  3024. X            {
  3025. X                /* make key match 'key' in beg */
  3026. X                beg = pos - 1;  /* skip back to beginning of match */
  3027. X                for (j = 0; j < key_len; j++) key[j] = *beg++;
  3028. X                return(pos - 1);
  3029. X            }
  3030. X          
  3031. X          else beg = pos;
  3032. X      }
  3033. X}
  3034. X
  3035. X
  3036. unsigned char *back_search_region(unsigned char *beg,unsigned char *end, unsigned char *key)
  3037. X{
  3038. X    char ch, ch2,char1,work[80];
  3039. X    unsigned char *pos;
  3040. X    int key_len,j, str_len;
  3041. X
  3042. X    if (CASE_SENSITIVE)
  3043. X      {
  3044. X          strcpy(work,key);
  3045. X          key_len = strlen(key);
  3046. X      }
  3047. X    else
  3048. X      {
  3049. X          /* upcase key */
  3050. X          key_len = 0;
  3051. X          while (ch = key[key_len],ch != '\0')
  3052. X            {
  3053. X                ch = upcase(ch);
  3054. X                work[key_len++] = ch;        /* null char is ok */
  3055. X            }
  3056. X      }
  3057. X    
  3058. X    str_len = (int) (end - beg);
  3059. X    if (str_len < key_len) return (EOB);
  3060. X    str_len = str_len - key_len; /* effective length */
  3061. X    beg += key_len;
  3062. X          
  3063. X    char1 = work[key_len - 1];
  3064. X    
  3065. X    while(1)
  3066. X      {
  3067. X          while (ch = *end, ch = upcase(ch), ch != char1)
  3068. X            {
  3069. X                if (beg > end) return(EOB);
  3070. X                end--;
  3071. X            }
  3072. X          end--;
  3073. X          /* so we have a position of possible match */
  3074. X
  3075. X          j = key_len - 2;
  3076. X          pos = end;  /* save this position so we start from here again */
  3077. X          while(ch = *end--, ch = upcase(ch),
  3078. X                ch2 = work[j], (ch == ch2) && (j >= 0)) j--;
  3079. X
  3080. X          if (j < 0)
  3081. X            {
  3082. X                /* make key match 'key' in beg */
  3083. X                end = pos +  1;  /* skip back to beginning of match */
  3084. X                for (j = key_len; j > 0; j--) key[j - 1] = *end--;
  3085. X                return(end + 1);
  3086. X            }
  3087. X          
  3088. X          else end = pos;
  3089. X      }
  3090. X}
  3091. X
  3092. X
  3093. X
  3094. int search(unsigned char *from, int repeat, int *col)
  3095. X{
  3096. X    /* return the line match was found as well as line number,
  3097. X       search from i on; assume that line_array match the i so we need
  3098. X       no initial lookup */
  3099. X
  3100. X    int test,j,save_line, the_col, row;
  3101. X    char ch, string[80];
  3102. X    unsigned char *pos, *save_pos, *found_at;
  3103. X
  3104. X    if ((from < BEG) || (from > EOB)) return(-1);
  3105. X    save_pos = C_POS;
  3106. X    save_line = C_LINE;
  3107. X    found_at = EOB;
  3108. X    *col = 0;
  3109. X
  3110. X    pos = from;
  3111. X    if (SEARCH_STR[0] != '\0')
  3112. X      {
  3113. X          test = repeat && (pos < EOB) && (pos >= BEG);
  3114. X          while(test)
  3115. X            {
  3116. X                if (SEARCH_DIR == 1)
  3117. X                  pos = forw_search_region(pos,EOB,(unsigned char*) SEARCH_STR);
  3118. X                else
  3119. X                  pos = back_search_region(BEG,pos,(unsigned char*) SEARCH_STR);
  3120. X                
  3121. X                
  3122. X                if (pos < EOB)
  3123. X                  {
  3124. X                      repeat--;
  3125. X                      found_at = pos;
  3126. X                      if (SEARCH_DIR == 1)
  3127. X                        pos += strlen(SEARCH_STR);
  3128. X                      else pos--;
  3129. X                  }
  3130. X                test = repeat && (pos < EOB) && (pos >= BEG);
  3131. X            }
  3132. X      }
  3133. X    
  3134. X    if (repeat) /* not found */
  3135. X      {
  3136. X          *col = 0;
  3137. X          if (SEARCH_STR[0] == '\0')
  3138. X            message("Search string not specified.",1);
  3139. X          else
  3140. X            {
  3141. X                (void) sprintf(string,"%s NOT FOUND.",SEARCH_STR);
  3142. X                message(string,1);
  3143. X            }
  3144. X          
  3145. X          row = -1;
  3146. X      }
  3147. X    else /* if ( !MOST_T_OPT && !MOST_B_OPT) */   /* expand tabs to get col correct */
  3148. X      {
  3149. X          find_row_column(found_at,&row,&the_col);
  3150. X          *col = apparant_distance(found_at);
  3151. X      }
  3152. X    C_POS = save_pos;
  3153. X    C_LINE = save_line;
  3154. X    if (row > 0) CURS_POS = found_at;
  3155. X    return( row );
  3156. X}
  3157. END_OF_FILE
  3158. if test 5318 -ne `wc -c <'search.c'`; then
  3159.     echo shar: \"'search.c'\" unpacked with wrong size!
  3160. fi
  3161. # end of 'search.c'
  3162. fi
  3163. if test -f 'search.h' -a "${1}" != "-c" ; then 
  3164.   echo shar: Will not clobber existing file \"'search.h'\"
  3165. else
  3166. echo shar: Extracting \"'search.h'\" \(208 characters\)
  3167. sed "s/^X//" >'search.h' <<'END_OF_FILE'
  3168. X#ifndef _DAVIS_SEARCH_H_
  3169. X#define _DAVIS_SEARCH_H_
  3170. X#include <stdio.h>
  3171. X#include <string.h>
  3172. X
  3173. extern int SEARCH_DIR;
  3174. X
  3175. extern int search(unsigned char *, int, int *);
  3176. extern int substring(char *, char *);
  3177. X#endif
  3178. X
  3179. END_OF_FILE
  3180. if test 208 -ne `wc -c <'search.h'`; then
  3181.     echo shar: \"'search.h'\" unpacked with wrong size!
  3182. fi
  3183. # end of 'search.h'
  3184. fi
  3185. if test -f 'sysdep.h' -a "${1}" != "-c" ; then 
  3186.   echo shar: Will not clobber existing file \"'sysdep.h'\"
  3187. else
  3188. echo shar: Extracting \"'sysdep.h'\" \(1876 characters\)
  3189. sed "s/^X//" >'sysdep.h' <<'END_OF_FILE'
  3190. X#ifndef __DAVIS_SYSDEP_H__
  3191. X#define __DAVIS_SYSDEP_H__
  3192. X
  3193. X#include <stdio.h>
  3194. X  
  3195. X#ifdef VMS
  3196. X#include <ssdef.h>
  3197. X#include <rmsdef.h>
  3198. X#include <dvidef.h>
  3199. X#include <jpidef.h>
  3200. X#include <libdef.h>
  3201. X#include <descrip.h>
  3202. X#include <iodef.h>
  3203. X#include <ttdef.h>
  3204. X#include <unixlib.h>
  3205. X#else
  3206. extern char *getenv( char *);
  3207. extern int read (int,  char *, int);
  3208. extern int unlink( char *);
  3209. extern int sleep(unsigned);
  3210. X#endif  
  3211. X  
  3212. X#ifdef VMS
  3213. extern unsigned long SHELL_PID;  
  3214. X
  3215. extern int do_shell_command();
  3216. extern int expand_file_name(char *,char *);
  3217. extern char *unix2vms(char *);
  3218. X
  3219. X#endif /* VMS */
  3220. X
  3221. X#ifdef VMS
  3222. typedef struct {                /* I/O status block     */
  3223. X        short i_cond;           /* Condition value      */
  3224. X        short i_xfer;           /* Transfer count     */
  3225. X        long  i_info;           /* Device information     */
  3226. X} iosb;
  3227. typedef struct {                /* Terminal characteristics   */
  3228. X        char  t_class;          /* Terminal class     */
  3229. X        char  t_type;           /* Terminal type      */
  3230. X        short t_width;          /* Terminal width in characters   */
  3231. X        long  t_mandl;          /* Terminal's mode and length   */
  3232. X        long  t_extend;         /* Extended terminal characteristics  */
  3233. X}  termchar;                    
  3234. X
  3235. short TTY_CHANNEL_GLOBAL;
  3236. X
  3237. X#else
  3238. X#define TTY_DESCR 2
  3239. extern int ioctl(int, int, ...);
  3240. X
  3241. X#ifdef BSD
  3242. X#include <sgtty.h>
  3243. X     struct ltchars  OLDTTY_LC;
  3244. X     struct tchars   OLDTTY_TC;
  3245. X     struct sgttyb   OLDTTY;
  3246. X#else
  3247. X#include <sys/termio.h>
  3248. X     struct termio OLDTTY;
  3249. X#endif
  3250. X#endif /* VMS */
  3251. X
  3252. extern int INPUT_BUFFER_LEN;
  3253. extern char INPUT_BUFFER[80];
  3254. X
  3255. extern void init_tty();
  3256. extern void reset_tty();
  3257. extern char getkey();
  3258. extern void ungetkey(char);
  3259. extern void sys_resume();
  3260. extern void get_term_dimensions(int *, int *);
  3261. extern int sys_delete_file(char *);
  3262. X
  3263. extern char *get_time();
  3264. X#endif /* __DAVIS_SYSDEP_H__ */
  3265. END_OF_FILE
  3266. if test 1876 -ne `wc -c <'sysdep.h'`; then
  3267.     echo shar: \"'sysdep.h'\" unpacked with wrong size!
  3268. fi
  3269. # end of 'sysdep.h'
  3270. fi
  3271. if test -f 'window.h' -a "${1}" != "-c" ; then 
  3272.   echo shar: Will not clobber existing file \"'window.h'\"
  3273. else
  3274. echo shar: Extracting \"'window.h'\" \(1726 characters\)
  3275. sed "s/^X//" >'window.h' <<'END_OF_FILE'
  3276. X#ifndef _DAVIS_WINDOW_H_
  3277. X#define _DAVIS_WINDOW_H_
  3278. X#include "buffer.h"
  3279. X
  3280. struct Window_Type
  3281. X  {
  3282. X      unsigned char *beg_pos;   /* buffer pos of top line */
  3283. X      int beg_line;             /* line number of top */
  3284. X      int curs_line;            /* line number of curs pos */
  3285. X      int curs_col;             /* column number of curs pos */
  3286. X      unsigned char *curs_pos;  /* pos of curs pos */
  3287. X      int col;                  /* column offset */
  3288. X      int n_lines;              /* number of lines of buffer (mode dependent) */
  3289. X      int top;                  /* screen location of top */
  3290. X      int bot;                  /* screen location of bot */
  3291. X      int display;              /* value of MOST_S_OPT for selective display */
  3292. X      char *status;             /* status line */
  3293. X      Buffer *buf;              /* buffer structure in window */
  3294. X      struct Window_Type *next; /* next window */
  3295. X      struct Window_Type *prev; /* prev window */
  3296. X      int flags;                /* Squeeze lines, etc.. */
  3297. X      int lock;                 /* true if locked */
  3298. X  };
  3299. typedef struct Window_Type Window;
  3300. X
  3301. extern Window *WIN;
  3302. extern Window *TOP_WIN;
  3303. extern int COLUMN;
  3304. extern int CURS_ROW;
  3305. extern int CURS_COL;
  3306. extern unsigned char *CURS_POS;
  3307. extern int RESTORE_WIDTH_TO;
  3308. extern void update_window(int); /* moves window to have arg lines on the top */
  3309. extern void update_status();
  3310. extern void redraw_window();    /* redraws window updating the structure */
  3311. extern void clear_window();
  3312. extern void window_buffer();
  3313. extern void init_display();
  3314. extern void reset_display();
  3315. extern void other_window(int);
  3316. extern void toggle_lock();
  3317. extern void set_window(Window *);
  3318. X
  3319. extern void message(char *, int);
  3320. extern void clear_minibuffer();
  3321. X#endif
  3322. END_OF_FILE
  3323. if test 1726 -ne `wc -c <'window.h'`; then
  3324.     echo shar: \"'window.h'\" unpacked with wrong size!
  3325. fi
  3326. # end of 'window.h'
  3327. fi
  3328. echo shar: End of archive 1 \(of 2\).
  3329. cp /dev/null ark1isdone
  3330. MISSING=""
  3331. for I in 1 2 ; do
  3332.     if test ! -f ark${I}isdone ; then
  3333.     MISSING="${MISSING} ${I}"
  3334.     fi
  3335. done
  3336. if test "${MISSING}" = "" ; then
  3337.     echo You have unpacked both archives.
  3338.     rm -f ark[1-9]isdone
  3339. else
  3340.     echo You still need to unpack the following archives:
  3341.     echo "        " ${MISSING}
  3342. fi
  3343. ##  End of shell archive.
  3344. exit 0
  3345.